Match Textbox Value in Range (Between values mentioned in two Cells)

waheed254

Board Regular
Joined
Jan 2, 2014
Messages
62
Hi There, I want to check text box value if matches between range defined accordingly..

Example

I have detail already given as under,
COLUMN ACOLUMN BCOLUMN C
ABC101200
DEF301400

Now i want to check Text box1 value which is ABC in Columns A
& check if text box2 value is within range of Column B to Column C Value if yes than ok if not Error Msg.

Can any one Guide
ABC can be more than once so all matches should be checked.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi,
Try following code I adapted from VBA help file (Range.FindNext Method)

VBA Code:
Private Sub CommandButton1_Click()
    Dim SearchValue(1 To 2) As Variant
    Dim firstaddress As String
    Dim FoundMatch As Boolean
    Dim c As Range
   
    SearchValue(1) = Me.TextBox1.Value
    SearchValue(2) = Val(Me.TextBox2.Value)

    With Worksheets(1).Columns(1)
         Set c = .Find(SearchValue(1), LookIn:=xlFormulas, lookat:=xlWhole)
         If Not c Is Nothing Then
            firstaddress = c.Address
            Do
               FoundMatch = CBool(SearchValue(2) >= c.Offset(, 1).Value And _
                                  SearchValue(2) <= c.Offset(, 2).Value)
                                 
               If FoundMatch Then GoTo DoneFinding
                Set c = .FindNext(c)
                If c Is Nothing Then GoTo DoneFinding
            Loop While c.Address <> firstaddress
          End If
    End With

DoneFinding:
    If FoundMatch Then
        MsgBox "Record Found"
    Else
        MsgBox "Record Not Found"
    End If

End Sub

Adjust code as required to meet specific project need

Dave
 
Upvote 0

Forum statistics

Threads
1,214,568
Messages
6,120,272
Members
448,953
Latest member
Dutchie_1

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