Run Time Error 91

rjplante

Well-known Member
Joined
Oct 31, 2008
Messages
567
Office Version
  1. 365
Platform
  1. Windows
I have an macro and it is failing on the last line in the code block. The worksheet that this is searching on does contain the text system options. When I select column A and perform a find for that text, it finds the exact row just fine. Yet when I run my macro, it fails on this line with a run time error 91 - Object Variable or With block variable not set. I have the range declared up above, so I don't know what the issue is. I have a second macro that executes a similar function and fails in the same manner (macro 2) with the last line failing to find the text. Why is the system unable to execute a find? The file is saved as .xlsm format so all of the macros should be working. I am confused...

Macro 1:
VBA Code:
Dim FindRow As Range

With Sheets("Pricing Sheet")
    Set FindRow = .Range("A:A").Find(What:="System Options", LookIn:=xlValues, LookAt:=xlWhole)
End With

Sheets("Pricing Sheet").Range("A" & FindRow.Row + 1).Select


Macro 2:
VBA Code:
Dim newLrow As Long
Dim GrandTotal As Range

With Sheets("Component List")
   Set GrandTotal = .Range("A:A").Find(What:="SYSTEM TOTAL", LookIn:=xlValues, LookAt:=xlWhole)
End With
        
newLrow = GrandTotal.Row
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
In both macros VBA procedures you forgot to check if the range is Nothing like you can see in the VBA help example.​
The Range.Find method always works when the logic is respected …​
 
Upvote 0
Try changing this part of your code:
VBA Code:
LookAt:=xlWhole
to this:
VBA Code:
LookAt:=xlPart
and see if that works.
 
Upvote 0
Marc, thanks for the input on that line. I agree it needs to be fixed, however, there seems to be something else going on. I restarted my computer to clean up any other possibilities and opened up a clean template of my workbook. I made some selections in column B for various rows. I then run a macro to filter out all rows greater than zero and any blank rows. When I run this macro it fails on the If then line below.

VBA Code:
With ActiveSheet.AutoFilter
    If .FilterMode = True Then
      .ShowAllData

What could be the cause of this failure. Everything else has run just fine before today and now it has started failing. It appears that the last update to Office 365 is on Jan 12. I was working on this last Tuesday and everything worked as expected. Then today, everything is wonky. I don't get it.
 
Upvote 0
Stumbled on the fix using dumb luck. I had a single column which had the filtering turned on for that column. My macros utilize that column for the filtering process. It somehow got turned off. All is better now that I turned the filtering back on for that column.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top