Trying to find if cell in range is exact match for criteria

Jeddo

Board Regular
Joined
Jan 26, 2019
Messages
50
Office Version
  1. 2019
Platform
  1. Windows
New to VBA and still trying to learn. I have a code to look in a column range and find if there is a numeric match for the value in a text box. It is working except for the problem I am having which is the formula is not finding an exact match. Example: I enter the number 61 in the text box. There is no 61 in the column range, but there is a 610, which the formula is recognizing as 61. Any help would be appreciated.

Dim rngCust As Range

Set rngCust = ActiveWorkbook.Worksheets("Auction Items").Range("B5:B180").Find(what:=Me.txtItem)

If rngCust Is Nothing Then

MsgBox "Item number does not exist"
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try the following:


Code:
Dim rngCust As Range
    If IsNumeric(Me.txtItem) Then valor = Val(Me.txtItem) Else valor = Me.txtItem
    Set rngCust = ActiveWorkbook.Worksheets("Auction Items").Range("B5:B180").Find( _
        what:=valor, LookIn:=xlValues, lookat:=xlWhole)
    '
    If rngCust Is Nothing Then
        MsgBox "Item number does not exist"
    Else
        MsgBox "Value : " & Me.txtItem.Value
    End If
 
Upvote 0
Try the following:


Code:
Dim rngCust As Range
    If IsNumeric(Me.txtItem) Then valor = Val(Me.txtItem) Else valor = Me.txtItem
    Set rngCust = ActiveWorkbook.Worksheets("Auction Items").Range("B5:B180").Find( _
        what:=valor, LookIn:=xlValues, lookat:=xlWhole)
    '
    If rngCust Is Nothing Then
        MsgBox "Item number does not exist"
    Else
        MsgBox "Value : " & Me.txtItem.Value
    End If

Thanks, that seems to do the trick. Way more than I ever could have figured out on my own. Thanks again
 
Upvote 0
Thanks, that seems to do the trick. Way more than I ever could have figured out on my own. Thanks again


Tip:
You can read the documentation in office, just search in google excel find.method, and you can do it with any excel instructions.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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