PC Review


Reply
Thread Tools Rate Thread

Display message if "find" command comes up blank ??

 
 
vrzimmerm@hotmail.com
Guest
Posts: n/a
 
      27th Sep 2007
At one point within a macro I'm searching a column for a specific text
using the "Find" command. If the search comes up empty I want to
display a message to the user and end the macro. How do I do this?

 
Reply With Quote
 
 
 
 
JW
Guest
Posts: n/a
 
      27th Sep 2007
One way:
Sub likeThis()
Dim found As Variant
Set found = Columns(1).Find(What:="gfdfg", _
After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, _
SearchFormat:=False)
If Not found Is Nothing Then
MsgBox "Found it"
Else
MsgBox "Didn't find it!"
End If
End Sub
vrzimm...@hotmail.com wrote:
> At one point within a macro I'm searching a column for a specific text
> using the "Find" command. If the search comes up empty I want to
> display a message to the user and end the macro. How do I do this?


 
Reply With Quote
 
=?Utf-8?B?TWF0dGhldyBQZmx1Z2Vy?=
Guest
Posts: n/a
 
      27th Sep 2007
How about something like this:

Sub ReportFindResults()

' Define search range
Dim myRange As Range
Set myRange = Range("a:a")

' Define value to search for
Dim ValueToFind As String
ValueToFind = "something"

With myRange
Dim c As Range
Set c = .Find(ValueToFind, LookIn:=xlValues)
If Not c Is Nothing Then
' do something
MsgBox "I found " & ValueToFind & "!"
Else
MsgBox ValueToFind & " was not found"
Exit Sub
End If
End With
End Sub


HTH,
Matthew Pfluger

"(E-Mail Removed)" wrote:

> At one point within a macro I'm searching a column for a specific text
> using the "Find" command. If the search comes up empty I want to
> display a message to the user and end the macro. How do I do this?
>
>

 
Reply With Quote
 
JE McGimpsey
Guest
Posts: n/a
 
      27th Sep 2007
One way:

Dim rFound As Range
Set rFound = Columns(1).Find("mytext")
If rFound Is Nothing Then
MsgBox "Didn't find 'mytext'"
Else
'your macro stuff here
End if


In article <(E-Mail Removed)>,
(E-Mail Removed) wrote:

> At one point within a macro I'm searching a column for a specific text
> using the "Find" command. If the search comes up empty I want to
> display a message to the user and end the macro. How do I do this?

 
Reply With Quote
 
vrzimmerm@hotmail.com
Guest
Posts: n/a
 
      27th Sep 2007
On Sep 27, 1:08 pm, JW <JWRIGH...@triad.rr.com> wrote:
> One way:
> Sub likeThis()
> Dim found As Variant
> Set found = Columns(1).Find(What:="gfdfg", _
> After:=ActiveCell, LookIn:=xlFormulas, _
> LookAt:=xlWhole, SearchOrder:=xlByRows, _
> SearchDirection:=xlNext, MatchCase:=False, _
> SearchFormat:=False)
> If Not found Is Nothing Then
> MsgBox "Found it"
> Else
> MsgBox "Didn't find it!"
> End If
> End Sub
>
> vrzimm...@hotmail.com wrote:
> > At one point within a macro I'm searching a column for a specific text
> > using the "Find" command. If the search comes up empty I want to
> > display a message to the user and end the macro. How do I do this?



Thanks, but I'm not sure how to fit this into my macro. What I'm
trying to do is activate the cell containing the first occurrence of
the text I'm searching for, and then delete that row and all rows
below it.


 
Reply With Quote
 
vrzimmerm@hotmail.com
Guest
Posts: n/a
 
      27th Sep 2007
On Sep 27, 1:16 pm, JE McGimpsey <jemcgimp...@mvps.org> wrote:
> One way:
>
> Dim rFound As Range
> Set rFound = Columns(1).Find("mytext")
> If rFound Is Nothing Then
> MsgBox "Didn't find 'mytext'"
> Else
> 'your macro stuff here
> End if
>
> In article <1190912131.834862.204...@19g2000hsx.googlegroups.com>,
>
> vrzimm...@hotmail.com wrote:
> > At one point within a macro I'm searching a column for a specific text
> > using the "Find" command. If the search comes up empty I want to
> > display a message to the user and end the macro. How do I do this?


Great stuff.....worked perfectly. Many thanks.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"reply all" command produces message "parameter value not valid" marcopolo Microsoft Outlook Discussion 2 23rd Aug 2008 05:12 PM
I am unable to find "new" under the "go" command to set up my news Madden Microsoft Outlook 1 24th May 2008 10:32 AM
can not find "resend message" command =?Utf-8?B?eG9uaw==?= Microsoft Access 1 5th Mar 2005 08:33 PM
Excel has a "Find Next" command but no "Find Previous" command. =?Utf-8?B?TWljaGFlbCBGaXR6cGF0cmljaw==?= Microsoft Excel Misc 2 10th Jan 2005 11:45 PM
Looking for a "previous" version in WMM with a "Black or Blank" Transitions Screen. Does ANYONE know were I can find it? This pack must have came with the ORIGINAL Movie Maker...NOT Fun Packs 2003. =?Utf-8?B?TmFu?= Windows XP MovieMaker 1 10th Mar 2004 04:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:39 PM.