MsgBox when Value not found.

Scarlacc

New Member
Joined
Apr 29, 2022
Messages
14
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Morning,
Having Trouble putting message box when my Text search result turns nothing found. tried doing if statement different ways but had no luck getting it to work. what it is doing is after if finds the Value from text box it will copy 7 rows down and 3 columns over and paste it on sheet 2 from sheet 5. Still need to add Screen control was waiting till i got it all done. included pics of the both sheets.

here is the Code that currently works to pull data from sheet5(Data Dump 2) to sheet2(Broker Search). just want a message box if it finds nothing instead of error you normally get.

Sub SearchStop5()

Sheets("Data Dump 2").Visible = True
Sheets("Data Dump 2").Select
Range("A1").Select
Range("A3").EntireColumn.Select

Selection.Find(What:=Sheet2.Cells(2, 4).Value, After:=ActiveCell, LookIn:=xlValues, _
Lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Select

ActiveCell.Range("A1:C7").Select
Selection.Copy
Sheets("Broker Search").Select
Range("G19").Select
ActiveSheet.Paste

Sheets("Data Dump 2").Visible = False

End Sub


Thanks
 

Attachments

  • Blank Search.png
    Blank Search.png
    28.3 KB · Views: 4
  • Data Dump.png
    Data Dump.png
    17.4 KB · Views: 4

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
The below may help:
VBA Code:
Sub SearchStop5()
    Dim wsDD2 As Worksheet
    Dim FindRng As Range
    
    Set wsDD2 = Sheets("Data Dump 2")
    Set FindRng = wsDD2.Range("A:A").Find(What:=Sheet2.Cells(2, 4).Value, Lookat:=xlPart)
    If Not FindRng Is Nothing Then
        MsgBox "Item found @ " & FindRng.Address
    Else
        MsgBox "Nothing found"
    End If
End Sub
 
Upvote 0
The below may help:
VBA Code:
Sub SearchStop5()
    Dim wsDD2 As Worksheet
    Dim FindRng As Range
   
    Set wsDD2 = Sheets("Data Dump 2")
    Set FindRng = wsDD2.Range("A:A").Find(What:=Sheet2.Cells(2, 4).Value, Lookat:=xlPart)
    If Not FindRng Is Nothing Then
        MsgBox "Item found @ " & FindRng.Address
    Else
        MsgBox "Nothing found"
    End If
End Sub
Thanks ill try tonight when at work and let you know
 
Upvote 0
it finds right where it is.. What im trying to do is from find selection copy over two columns and down six rows to the search sheet. witch i accomplished with code I wrote just cant seem to figure out a message box if it turns up nothing. Having a hard time learning the if's and loops sure with practice and time i will get it down.
 
Upvote 0
No other Help Needed i forgot about the If Error GoTo Statement. That fixed my issue. here is what i did.

Sub SearchStop5()

On Error GoTo TryAgain

Sheets("Data Dump 2").Visible = True
Sheets("Data Dump 2").Select
Range("A1").Select
Range("A3").EntireColumn.Select

Selection.Find(What:=Sheet2.Cells(2, 4).Value, After:=ActiveCell, LookIn:=xlValues, _
Lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Select

ActiveCell.Range("A1:C7").Select
Selection.Copy
Sheets("Broker Search").Select
Range("G19").Select
ActiveSheet.Paste

Sheets("Data Dump 2").Visible = False

Exit Sub

TryAgain:
MsgBox "Customer Not Found", , "Try Again"
Sheets("Data Dump 2").Visible = False

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,063
Messages
6,122,930
Members
449,094
Latest member
teemeren

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