cmschmitz24
Board Regular
- Joined
- Jan 27, 2017
- Messages
- 150
I tried reusing an existing code that works for a different spreadsheet to update it and use it with a new spreadsheet and data set but it's bugging out. Someone please help It bugs out on "Rng.EntireRow.Copy Worksheets("REH Annuitant").Range("A" & lastrow2 + 1)". The third to last row of code.
*Data in columns D/E has been removed.
VBA Code:
Sub TEST()
'Moves REH Annuitants to a New Sheet
Dim Rng As Range, r As Long, lastrow2 As Long, Lastrow As Long
Application.ScreenUpdating = False
Lastrow = Worksheets("MSC").UsedRange.Rows.Count
lastrow2 = Worksheets("REH Annuitant").UsedRange.Rows.Count
If lastrow2 = 1 Then lastrow2 = 0
For r = Lastrow To 2 Step -1
If Range("G" & r).Value = "S" Then
If Rng Is Nothing Then
Set Rng = Range("A" & r)
Else
Set Rng = Union(Rng, Range("A" & r))
End If
End If
Next r
Rng.EntireRow.Copy Worksheets("REH Annuitant").Range("A" & lastrow2 + 1)
Rng.EntireRow.Delete
Application.ScreenUpdating = True
End Sub
*Data in columns D/E has been removed.