Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Display message if "find" command comes up blank ??

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?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Display message if "find" command comes up blank ??

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
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?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default Display message if "find" command comes up blank ??

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

" 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?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Display message if "find" command comes up blank ??

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 . 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?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Display message if "find" command comes up blank ??

On Sep 27, 1:08 pm, JW 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

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.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Display message if "find" command comes up blank ??

On Sep 27, 1:16 pm, JE McGimpsey 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 . 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Display "macro-free workbooks - VB project message" on closing Exc Gary Nguyen Excel Discussion (Misc queries) 4 April 4th 23 11:41 AM
How to have a macro simply issue the "find" command or "control f: Charles Adams Excel Programming 3 February 6th 09 06:34 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Error message "Not enough system resources to display completely." MKode Excel Discussion (Misc queries) 1 March 2nd 06 12:00 PM
FileCopy Command Giving "Subscript Out of Range" Error Message Jim Hagan Excel Programming 2 June 15th 05 06:07 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"