Home > OS >  how to continue a macro if above "if" is true
how to continue a macro if above "if" is true

Time:10-07

So I have the above code, I want to continue on this logic: if K4 is not empty then copy L3 to L4 and so on, until one cell is empty (for example K32 is not empty then copy L31 to L32, but if K33 is empty then stop) Im sorry if this is a basic question, I have just started working with VBA. Thank you in advance

   Sub kepletmasolos()

Sheets("XTR MSTR").Select

 If IsEmpty(Range("K3").Value) = False Then

      Range("L2").Copy Range("L3")

   End If

End Sub

CodePudding user response:

Here is one way, using a Do loop:

Sub kepletmasolos()

Dim r As Long: r = 3

With Sheets("XTR MSTR")
    Do Until IsEmpty(.Cells(r, "K"))
        '.Cells(r, "L").Value = .Cells(r - 1, "L").Value
        .Cells(r - 1, "L").copy .Cells(r, "L")
        r = r   1
    Loop
End With

End Sub

CodePudding user response:

new to VBA myself, Just thought i would through my idea in?

row = where you would start, let me know what you think.

Sub kepletmasolos()

Dim Row As Long 
Row = 1

Start:
With Sheets("XTR MSTR")
    If Not isEmpty(.Cells(Row, "K")) Then
        .Cells(Row, "L").Copy .Cells(Row   1, "L")
        Row = Row   1
        GoTo Start
    Else
End If
End With

End Sub
  • Related