Finding a value - error correction

Logistix

Board Regular
Joined
Aug 23, 2006
Messages
77
Hi there,

I have a userform that currently locates a particular cell (value) when I push the find button. Im a little stuck, bacause when I input a number not in the column (or blank for that matter).

I get the error "Select method of Range Class failed".

Does anyone know how to do a check to see if the value exists in the column, and if not prompt the user that the number is invalid and to re-enter.

Here's the code I have so far:

Code:
Private Sub FindButton_Click()
    
    Worksheets("Records").Range("A:A").Find(TransactionNoBox.Value).Select   ' This finds my value
    
    TransactionNumberForm.Hide
    DeleteConfirmationForm.Show
    
End Sub

I think I need a while loop here but am not too familiar with them yet. Thanks in advance.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hey one more thing....

If I leave the TransactionNoBox empty, and press find, it still prompts me with the msgbox delete. Do you know what has happened here
 
Upvote 0
Yup!
change..

Code:
Private Sub FindButton_Click()
Dim r As Range
   If TransactionNoBox="" Then Exit Sub
   Set r = Sheets("Records").Columns("a").Find(TransactionNoBox.Text,,,xlWhole)
   If Not r Is Nothing Then
      If vbYes = MsgBox("Delete?",vbYesNo,"Confirm") Then
         r.EntireRow.Delete
      End If
   Else
      MsgBox "Not Found"
   End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,986
Messages
6,128,115
Members
449,423
Latest member
Mike_AL

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