|
-
Jan 26th, 2005, 03:34 PM
#1
Thread Starter
Hyperactive Member
Selection.Find, true or false?
I have the following code:
Code:
Range("B7:AA7").Select
Selection.Find(What:=strWT, After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
If the string in strWT is not found, it errors out.
How can I test it to find out if it found the strWT or ont, so that i can pop up a message that says Can not find strWT?
Looked for an answer on the posts, but couldn't find anything specific to the above.
Last edited by jeffcravener; Jan 27th, 2005 at 08:36 AM.
Reason: [Resolved]
-
Jan 26th, 2005, 05:09 PM
#2
Re: Selection.Find, true or false?
A Find will return a range. so if you set a range to a Find and then test the
range you can determine if it was found or not.
VB Code:
Dim r As Range
Set r = Sheets(1).Cells.Find(what:="#11#")
If TypeName(r) <> "Nothing" Then
MsgBox r.Cells.Row & " - " & r.Cells.Column
r.Replace what:="#11#", Replacement:="#22#"
Else
MsgBox "Not found"
End If
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 27th, 2005, 08:35 AM
#3
Thread Starter
Hyperactive Member
-
Jan 27th, 2005, 03:17 PM
#4
Re: Selection.Find, true or false?
No problem. I remembered I wrote the code recently. So easy for me.
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 27th, 2005, 03:33 PM
#5
Thread Starter
Hyperactive Member
Re: Selection.Find, true or false?
Actually.....a related question.
The code is within a loop...so I am trying to clear R, so it does equal nothing befoe the next iteration.
But, it is holding the last value.
I tried:
Set r = Nothing
But its not working.
-
Jan 27th, 2005, 03:39 PM
#6
Re: Selection.Find, true or false?
Weird, could you post the code?
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 27th, 2005, 03:41 PM
#7
Thread Starter
Hyperactive Member
Re: Selection.Find, true or false?
Ignore me!!!
I figured out wah t iwas doing.
It was finding the string in another location on the page.
so i changed Cells.Find to Selection.Find.
sorry for the bother!
Last edited by jeffcravener; Jan 27th, 2005 at 03:56 PM.
-
Jan 27th, 2005, 04:18 PM
#8
Re: Selection.Find, true or false?
Dont worry about it. We all have those days.
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 
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
|