excelerino
New Member
- Joined
- Nov 2, 2016
- Messages
- 47
Hi guys,
I have this code (part of a larger macro, so ignore the lack of opening/end statements):
Dim ws1 As Worksheet, ws2 As Worksheet
Set ws1 = Sheet1
Set ws2 = Sheet9
With ws1
ws1LRow = .Range("A" & .Rows.Count).End(xlUp).Row
End With
With ws2
ws2LRow = .Range("A" & .Rows.Count).End(xlUp).Row
End With
If ws2LRow Like ws1LRow Then
End If
If Not ws2LRow Like ws1LRow Then
Sheet9.Rows(20).EntireRow.Copy
Sheet9.Activate
ActiveSheet.Range("A4000").End(xlUp).Select
Selection.Offset(1, 0).Select
ActiveSheet.Paste
End If
It checks if the last rows in 2 sheets are the same, if not it copies a row to the second sheet (making them equal again, theoretically). It works perfectly, but only if 1 row is added! If 2 or more rows are added in the first sheet, it will only add 1 row and then end the process. Of course I can run it again (and again with multiple rows) until they are equal, but having a loop would obviously be more useful. I just don't quite know the syntax! So if anyone could help, that would be much appreciated
I have this code (part of a larger macro, so ignore the lack of opening/end statements):
Dim ws1 As Worksheet, ws2 As Worksheet
Set ws1 = Sheet1
Set ws2 = Sheet9
With ws1
ws1LRow = .Range("A" & .Rows.Count).End(xlUp).Row
End With
With ws2
ws2LRow = .Range("A" & .Rows.Count).End(xlUp).Row
End With
If ws2LRow Like ws1LRow Then
End If
If Not ws2LRow Like ws1LRow Then
Sheet9.Rows(20).EntireRow.Copy
Sheet9.Activate
ActiveSheet.Range("A4000").End(xlUp).Select
Selection.Offset(1, 0).Select
ActiveSheet.Paste
End If
It checks if the last rows in 2 sheets are the same, if not it copies a row to the second sheet (making them equal again, theoretically). It works perfectly, but only if 1 row is added! If 2 or more rows are added in the first sheet, it will only add 1 row and then end the process. Of course I can run it again (and again with multiple rows) until they are equal, but having a loop would obviously be more useful. I just don't quite know the syntax! So if anyone could help, that would be much appreciated