VBA code: If not found then Msgbox

omairhe

Well-known Member
Joined
Mar 26, 2009
Messages
2,040
Office Version
  1. 2019
Platform
  1. Windows
Hey everyone,

How are u? Could you please help me with the code below that searches in column A, a word that begins with bel. All working great, but if it isn't found then pop up a message for 1 second "Entry not found".

Code:
Sub search_bel()   
   Dim Fnd As Range
   Set Fnd = Range("A:A").Find("bel*", , xlValues, xlWhole, , , False, False)
   If Not Fnd Is Nothing Then Cells(Fnd.Row, ActiveCell.Column).Activate
End Sub


Thanks and appreciation.
 
Last edited:

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
See if this suits your needs.

Code:
Sub search_bel()
Dim Fnd As Range, s As Variant
   Set Fnd = Range("A:A").Find("bel*", , xlValues, xlWhole, , , False, False)
   If Not Fnd Is Nothing Then 
        Cells(Fnd.Row, ActiveCell.Column).Activate
   Else
        With ActiveSheet
            Set newWordArt = .Shapes.AddTextEffect(PresetTextEffect:=msoTextEffect1, Text:="ENTRY NOT FOUND", FontName:="Times New Roman", _
                FontSize:=32, FontBold:=False, FontItalic:=False, Left:=ActiveWindow.UsableWidth / 2 - 200, Top:=10)
            s = Timer + 1
                Do While Timer < s
                    DoEvents
                Loop
            newWordArt.Delete
        End With
   End If
End Sub
 
Last edited:
Upvote 0
See if this suits your needs.

Code:
Sub search_bel()
Dim Fnd As Range, s As Variant
   Set Fnd = Range("A:A").Find("bel*", , xlValues, xlWhole, , , False, False)
   If Not Fnd Is Nothing Then 
        Cells(Fnd.Row, ActiveCell.Column).Activate
   Else
        With ActiveSheet
            Set newWordArt = .Shapes.AddTextEffect(PresetTextEffect:=msoTextEffect1, Text:="ENTRY NOT FOUND", FontName:="Times New Roman", _
                FontSize:=32, FontBold:=False, FontItalic:=False, Left:=ActiveWindow.UsableWidth / 2 - 200, Top:=10)
            s = Timer + 1
                Do While Timer < s
                    DoEvents
                Loop
            newWordArt.Delete
        End With
   End If
End Sub

Yes. A big thumbs up.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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