ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Response to txtbox content if not found in the worksheets: Excel V (https://www.excelbanter.com/excel-programming/439540-response-txtbox-content-if-not-found-worksheets-excel-v.html)

Msgbox Data not found

Response to txtbox content if not found in the worksheets: Excel V
 
Hi,
Everyone,

I've a worksheet in a workbook that has a Search text Box created from the
control box.
I'd like to know the code that generates Msgbox "Data not found!!", when the
search button is clicked.


Dave Ramage[_4_]

Response to txtbox content if not found in the worksheets: Excel V
 
Add this to the relevant sheet code module:

Private Sub CommandButton_Search_Click()
'''Search this worksheet for text in TextBox_Search
'''If found, then activate cell, if not found, then display message
Dim r As Excel.Range

Set r = Me.Cells.Find(What:=Me.TextBox_Search, LookIn:=xlValues)
If r Is Nothing Then
MsgBox prompt:="Data not found!"
Else
r.Activate
End If
End Sub

Change the control names as required.

Cheers,
Dave

"Msgbox "Data not found"" wrote:

Hi,
Everyone,

I've a worksheet in a workbook that has a Search text Box created from the
control box.
I'd like to know the code that generates Msgbox "Data not found!!", when the
search button is clicked.



All times are GMT +1. The time now is 12:03 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com