Why 'Run-time error '91', Object variable or with block variable not set'

Vantom

Board Regular
Joined
Feb 28, 2014
Messages
65
Code:
With Sheets("Sheet2"): Dim Rng As Range: Set Rng = .Range("Sheet2!A:A"): End With
Dim lngDateRow As Long, vFromDate As Variant: vFromDate = Range("Sheet1!B5").Value
    With Sheets("Sheet2"): lngDateRow = Rng.Find(What:=vFromDate , LookIn:=xlValues, 
          LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False,
              SearchFormat:=False).Row: End With ': MsgBox lngDateRow
'vFromDate' is something like '42213.6370138889'.
 
Last edited:
Another cause of errors was that numbers(for example date/time number ending in 1666) was rounded up(1667) when put in a named range(when date was clicked in a listbox, a named range was created with the date/time formatted as a 10 decimal number, and then the rounded up named ranges were written to the cells Sheet1!B5(FromDate)/Sheet1!B7(ToDate) that .find was to find. Solution is to write the date/time numbers directly to the cells Sheet1!B5(FromDate)/Sheet1!B7(ToDate)when a date is clicked in on of the listboxes, and then put the cell values in named ranges(as a result the date/time numbers does not get rounded up).
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
That's exactly what I've been trying to tell you since back in post #8.
The values changed at some point between going from the original sheet to another sheet, then to a listbox, then back to the sheet.
 
Upvote 0
Yes, .find searched for e.g. the variable 42220.579655(where 0s had been removed), when cell content in Sheet2 was 42220.5796550000, solved by 'LookAt' 'xlPart', instead of 'xlWhole'. And the rounded up numbers, solved by changing the order in which the date/time number are written to named range/cell, cell first, named second, insted of the other way around.
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,637
Latest member
Ezio2866

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