Why is this a runtime 91 error?

vbaNumpty

Board Regular
Joined
Apr 20, 2021
Messages
171
Office Version
  1. 365
Platform
  1. Windows
I am following a tutorial that demonstrates how to use advancedfilter and find functions in VBA code to populate a list box and allow for editing of values. Despite following along and triple checking that my code matches that of the video, when the following code is run I get a runtime 91 error while in the video tutorial the code runs fine. The error is happening on the last line of code, FindMe.Select.

VBA Code:
Sub Macro7()
'
' Macro7 Macro

    Set FindMe = Range("A4:L30").Find(What:="06-May-21", LookIn:=xlValues, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)
    FindMe.Select
End Sub
 
So search for this value rather than a text …​
As it works manually so redo it just activating before the Macro Recorder in order to compare the parameters used …​
I have tried with the number value of the date, and it does not work either through the code or manually.
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
As the Excel basics like here its Find feature - VBA help must read ! - always works when the Logic is respected​
so compare the parameters with the Macro Recorder …​
 
Upvote 0
I have even now tried the following after recording a new macro that worked while I was manually doing the steps, but fails when trying to run the VERY CODE that was made doing those steps manually. At a complete loss right now.

VBA Code:
Sub Macro4()
'
' Macro4 Macro
'

'
    Application.FindFormat.NumberFormat = "d-mmm-yy"
    Cells.Find(What:="06-May-21", After:=ActiveCell, LookIn:=xlValues, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=True).Activate
    Cells.FindNext(After:=ActiveCell).Activate
End Sub
 
Upvote 0
Your format and data do NOT match.

"06-May-21" would have a Custom format of "dd-mmm-yy", not "d-mmm-yy".
It does make a difference to your code.

Out of curiosity, where are you located?
European version of Excel VBA and American version of Excel VBA handle dates a little differently.
So I was wondering if that may be why I cannot recreate your issues.
 
Upvote 0
But you still search a text rather than a date … And of course just follow the VBA help example this error can not raise …​
To avoid a NES according to this obvious point link your workbook with a files host website …​
(NES : Never Ending Story …)
 
Upvote 0
Your format and data do NOT match.

"06-May-21" would have a Custom format of "dd-mmm-yy", not "d-mmm-yy".
It does make a difference to your code.

Out of curiosity, where are you located?
European version of Excel VBA and American version of Excel VBA handle dates a little differently.
So I was wondering if that may be why I cannot recreate your issues.

I added a the second d to the format and I get a run time error 1004 in doing so.

I just dont understand why it works doing the manual use of the find me, but when I record the macro and don't change a single thing in the code it errors out. Isn't it recording what I did successfully?
 
Upvote 0
It's not you as the Recorder is not friendly with your 'dates' …​
Read post #15 …​
 
Upvote 0
But you still search a text rather than a date … And of course just follow the VBA help example this error can not raise …​
To avoid a NES according to this obvious point link your workbook with a files host website …​
(NES : Never Ending Story …)
I have tried to let it search the date, I guess I am not understanding exactly what you have been trying to convey. Here is a link to a google drive:


The code in question is in Module 3 and I was testing it on the Orders Sheet
 
Upvote 0
Search which date on which worksheet ?​
 
Upvote 0
Search which date on which worksheet ?​
I was using "06-May-21" as can be seen in the code, it will be replaced with a variable in the future that is user selected, and it is searching the range A4:L30 on the Orders sheet (last one)
 
Upvote 0

Forum statistics

Threads
1,215,692
Messages
6,126,227
Members
449,303
Latest member
grantrob

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