Hi, I'm trying to make a short macro to copy all rows with data in a certain column to a new sheet but every time I run it I get the error
"Run-time error '91':
Object variable or With block variable not set"
When I debug it is the totalRows variable that is highlighted.
I don't have the issue when I use the same variable in a different macro. What am I doing wrong???
"Run-time error '91':
Object variable or With block variable not set"
When I debug it is the totalRows variable that is highlighted.
I don't have the issue when I use the same variable in a different macro. What am I doing wrong???
Code:
Sub filteredPayables()
Sheets.Add after:=Sheets(1)
Dim x As Long
Dim totalRows As Long
x = 1
totalRows = Cells.Find(What:="*", _
after:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Do While x < totalRows
If Range(x, 6) <> 0 Then
ActiveWorkbook.Sheets(1).Rows(x).EntireRow.Copy
ActiveWorkbook.Sheets(2).Range("A1").End(xlDown).Offset(1, 0).EntireRow.Paste
x = x + 1
Else
x = x + 1
End If
Loop
End Sub
Last edited by a moderator: