Error 91 in code - Object variable or with block not set

Galego

New Member
Joined
May 8, 2017
Messages
39
Code below

Code:
Sub AddNEW()
'
' AddNEW Macro
'

    Application.ScreenUpdating = False
    Dim LastRow As Long
    Dim wsData As Worksheet
    Dim wsMacro As Worksheet
    Set wsData = Workbooks("Over 50k Report.xlsm").Sheets("NEW Invoices")
    Set wsMacro = Workbooks("Over 50k Report.xlsm").Sheets("Over 50k")
    LastRow = wsData.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    wsData.Range("J1:J" & LastRow).AutoFilter Field:=1, Criteria1:="NEW"
    wsData.Range("D2:D" & LastRow).SpecialCells(xlCellTypeVisible).Copy wsMacro.Cells(wsMacro.Rows.Count, "A").End(xlUp).Offset(1, 0)
    If wsData.AutoFilterMode = True Then wsData.AutoFilterMode = False
    Application.ScreenUpdating = True


'
End Sub
 

Some videos you may like

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Galego

New Member
Joined
May 8, 2017
Messages
39
can anyone please help me fix the error?

Not sure what I am missing.

Thanks,
David
 

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
6,102
Office Version
  1. 2019
Platform
  1. Windows
can anyone please help me fix the error?

Not sure what I am missing.

Thanks,
David


Hi,
this line

Code:
LastRow = wsData.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

will give that error if there is no data on your NEW Invoices worksheet.

Dave
 

Galego

New Member
Joined
May 8, 2017
Messages
39
Odd enough now works.

Not sure if there was an extra space there in the name.

Cheers.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,397
Messages
5,528,495
Members
409,820
Latest member
gabrielrms

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top