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
CallumDA
  • 12,025
  • 6
  • 30
  • 52
Chandrasekar R
  • 113
  • 2
  • 12

2 Answers2

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
ASH
  • 20,759
  • 19
  • 87
  • 200
0
If isEmpty(Range(x)) then exit do end if
Anthony
  • 116
  • 2
  • 9