Excel VBA copy and paste loop with logic condition

Solved/Closed
Yogibearv Posts 2 Registration date Monday 20 October 2014 Status Member Last seen 21 October 2014 - 20 Oct 2014 à 19:34
 Yogibearv - 28 Oct 2014 à 16:27
Hi,

I am new to VBA and would appreciate some help with a problem I am trying to solve.

I would like a macro that is able to copy information from a cell (in this case I7) into another on the same worksheet (B7). I then would like the macro to check what is written in Cell D5, If the value is "NO", then copy I8 to B8 and so on (offset by one row). When D5 changes to "OK" I would like the macro to stop.

Many thanks in advance!

4 responses

TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 555
28 Oct 2014 à 12:19
Hi Yogibearv,

So you use a formula for D5, that makes more sense. Try this code:
Sub RunMe()
Dim lRow, x As Integer

lRow = Range("I" & Rows.Count).End(xlUp).Row
x = 6

Do
    x = x + 1
    Range("B" & x).Value = Range("I" & x).Value
    Range("I" & x).ClearContents
Loop Until IsEmpty(Range("I" & x + 1)) Or x = lRow Or Range("D5").Value = "OK"

End Sub


Best regards,
Trowa