|
-
Jan 24th, 2005, 09:17 AM
#1
Thread Starter
Addicted Member
Coded Search in Excel 2002 not working
i have the following code in a module:
Code:
Dim StartDate as Date
ActiveSheet.Range("A1").Select
Activesheet.Cells.Find(What:=StartDate, After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
StartDate = 17/01/05 (variable taken from another sheet)
when i manually search the sheet, it finds the above entry, but when i use the code, it fails with 'Object variable or With block variable not set'
i have tried formating the date as dd/mm/yyyy, but still not working. I have a feeling it is to do with formats, but not sure, as it will find a string, just not this date.
I have also tried recording the same search via excel, but it still wont work.
i found this on MSKB: Run Time Error 91
could it be something to do with this?
any ideas?
TIA
Brian
if you fail to plan, you plan to fail
-
Jan 24th, 2005, 12:35 PM
#2
Re: Coded Search in Excel 2002 not working
It could be that .Find is not evaluating the variable contents, but instead
searching for the literal text? Test it out by hardcoding the date in the
What:= parameter.
HTH
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 24th, 2005, 01:13 PM
#3
Thread Starter
Addicted Member
Re: Coded Search in Excel 2002 not working
 Originally Posted by RobDog888
It could be that .Find is not evaluating the variable contents, but instead
searching for the literal text? Test it out by hardcoding the date in the
What:= parameter.
HTH
yep,
tried this as well:
Code:
Activesheet.Cells.Find(What:="17/01/05", After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
still doesnt work, and same error..
if you fail to plan, you plan to fail
-
Jan 24th, 2005, 01:22 PM
#4
Re: Coded Search in Excel 2002 not working
If the column is formatted as a Date then try passing a search criteria with
the '#' character surrounding the date value.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 25th, 2005, 07:38 AM
#5
Thread Starter
Addicted Member
Re: Coded Search in Excel 2002 not working
 Originally Posted by RobDog888
If the column is formatted as a Date then try passing a search criteria with
the '#' character surrounding the date value.
I had thought of this as well.
heres a couple of things i have tried:
Code:
Cells.Find(What:="#" & StartDate & "#", After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
doesnt work
Code:
Cells.Find(What:=#StartDate#, After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
It doesnt like this code
or this:
Code:
Cells.Find(What:='#StartDate#', After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
also:
Code:
StartDate = "#" & StartDate & "#"
prior to the search (had to declare the variable as a variant)
I cant think how else to do this!
I have also tried declaring the StartDate variable as a variant, and string and it still doesnt work. variant gives same error, and string doesnt work with other segments of my code so doesnt get this far.
thanks
if you fail to plan, you plan to fail
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|