0

I have created a Looping VBA to update values according to data in Columns A,B,C,D. But I need to stop this Looping once 'D' Column is empty or has no values.

Sub Macro1()
'
    ' Set Do loop to stop when an empty cell is reached.

Do Until IsEmpty(ActiveCell)

    Range("C2").Select
    Range("C2").End(xlDown).Offset(1, -2).Select
    Selection.ClearContents

    Range("C2").End(xlDown).Offset(0, -2).Select
    Range(Selection, Selection.End(xlUp)).Select
    Selection.FillDown

    Range("C2").End(xlDown).Offset(1, 0).Select
    ActiveCell.FormulaR1C1 = "Logged out"

    ActiveCell.Offset(1, 0).Select

    Loop

End Sub

2 Answers 2

1

There are many ways to accomplish this task. Here is one method.

Sub Test1()
'UpdatebyExtendoffice20161222
      Dim x As Integer
      Application.ScreenUpdating = False
      ' Set numrows = number of rows of data.
      NumRows = Range("D1", Range("D1").End(xlDown)).Rows.Count
      ' Select cell D1.
      Range("D1").Select
      ' Establish "For" loop to loop "numrows" number of times.
      For x = 1 To NumRows
         ' Insert your code here.
         ' Selects cell down 1 row from active cell.
         ActiveCell.Offset(1, 0).Select
      Next
      Application.ScreenUpdating = True
End Sub
Sign up to request clarification or add additional context in comments.

Comments

0
If isEmpty(Range(x)) then exit do end if

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.