Excel VBA copy and paste loop with logic condition

Solved/Closed
Yogibearv Posts 2 Registration date Monday October 20, 2014 Status Member Last seen October 21, 2014 - Updated on Jan 30, 2019 at 08:33 AM
 Yogibearv - Oct 28, 2014 at 04:27 PM
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!
Related:

4 responses

TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 552
Oct 28, 2014 at 12:19 PM
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
11