I have a loop that searches for a "False" outcome where two columns are being compared. If it finds a false outcome it will create a space in the column with the missing information by cutting and moving the column down one cell. It should continue to do this until all of the false outcomes have been resolved.
The issue I am running into is that when it reaches the bottom and there is nothing to copy because it is the last row that is false it stops and gives an error.
I need to add to this to say that if it gives this error to do something else (which would just be to go over one cell to the left and copy and paste back in the empty cell).
The called out line of ActiveSheet.Paste is where it is stopping at.
lr = Range("B" & Rows.Count).End(xlUp).Row
Dim r As Range
Set r = Range("E:E").Find(what:="FALSE", After:=ActiveCell, LookIn:=xlValues)
With Worksheets("GL Detail2").Range("E:E").Select
If Not r Is Nothing Then
firstAddress = r.Address
Do
Selection.Find(what:="FALSE", After:=ActiveCell, LookIn:=xlValues, _
lookat:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=True, SearchFormat:=False).Activate
ActiveCell.Offset(0, -1).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Cut
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(-1, -1).Select
Selection.Copy
ActiveCell.Offset(0, 1).Select
ActiveCell.PasteSpecial
Application.CutCopyMode = False
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("E2").Select
Selection.AutoFill Destination:=Range("E2:E" & lr)
Range("E2:E" & lr).Select
Selection.FindNext(After:=ActiveCell).Activate
Worksheets("GL Detail2").Range("E:E").Select
Loop While Not r Is Nothing
End If
End With
End Sub
The issue I am running into is that when it reaches the bottom and there is nothing to copy because it is the last row that is false it stops and gives an error.
I need to add to this to say that if it gives this error to do something else (which would just be to go over one cell to the left and copy and paste back in the empty cell).
The called out line of ActiveSheet.Paste is where it is stopping at.
lr = Range("B" & Rows.Count).End(xlUp).Row
Dim r As Range
Set r = Range("E:E").Find(what:="FALSE", After:=ActiveCell, LookIn:=xlValues)
With Worksheets("GL Detail2").Range("E:E").Select
If Not r Is Nothing Then
firstAddress = r.Address
Do
Selection.Find(what:="FALSE", After:=ActiveCell, LookIn:=xlValues, _
lookat:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=True, SearchFormat:=False).Activate
ActiveCell.Offset(0, -1).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Cut
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(-1, -1).Select
Selection.Copy
ActiveCell.Offset(0, 1).Select
ActiveCell.PasteSpecial
Application.CutCopyMode = False
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("E2").Select
Selection.AutoFill Destination:=Range("E2:E" & lr)
Range("E2:E" & lr).Select
Selection.FindNext(After:=ActiveCell).Activate
Worksheets("GL Detail2").Range("E:E").Select
Loop While Not r Is Nothing
End If
End With
End Sub