Could someone please let me know why this loop stops prematurely (row 105) i.e. before it reaches the cell with the text "STOP" in it (row 3000). It is trawling through a database copied into excel & copies the row (to another location) after the row that contains the text "Premises:"
Thank you
PHP Code:
Sub LoopThroughRows()
Dim n As Integer
Dim wsSource As Worksheet
Dim wsTarget As Worksheet
Dim row1 As Integer
Set wsTarget = Sheets("Output")
Set wsSource = Sheets("Data")
row1 = 1
wsSource.Select
'set n=2 to start in the second row
n = 2
'continue loop while the cell is not empty
Do Until Cells(n, 1) = "STOP"
If Cells(n, 1).Text = "Premises:" Then
Cells(n, 1).Select
ActiveCell.Offset(1, 0).Select
ActiveCell.EntireRow.Copy wsTarget.Cells(row1, 1)
row1 = row1 + 1
wsSource.Select
End If
'move to next row
n = n + 1
'Stop
Loop
End Sub
Bookmarks