Troubleshooting- Code that searches content from two userform textboxes against 2 correspoing worksheet columns

bensdb

New Member
Joined
Jan 24, 2014
Messages
18
Hi- I've been desperately trying to do this for hours to no avail. Im learning VBA and have bodged together the following, but I know the for loop that I have got in there cant be right.

Ive got a worksheet with First Name in Column B and Last Name in Column C.

From a userform with two Textboxes, one for first name, and the second for the last name, I need to run a search to find out if there is a match.

For some weird reason this code works about 60/70% of the time in finding matches, but then quite often it comes out as no match when there is!!

I know my code is a bit of a mess and the loop is almost certainly wrong.

PLEASE Help ME!!!!!!!




Sub findmatches()
Set sdsheet = ThisWorkbook.Sheets("Kids")
sdLR = sdsheet.Cells(Rows.Count, 1).End(xlUp).Row
newrng = sdsheet.Range("B1:B" & sdLR)


stringya = findfrm.blah1.Text
stringyb = findfrm.blah2.Text


stringy1 = "*" & stringya & "*"
stringy2 = "*" & stringyb & "*"


If sdsheet.Cells(Rows.Count, 1).End(xlUp).Row = 1 Then
sdLR = 2
Else
sdLR = sdsheet.Cells(Rows.Count, 1).End(xlUp).Row
End If

If IsError(Application.Match(stringy1, newrng, 0)) Then

Else


For X = 2 To sdLR

myvalue1 = Application.Match(stringy1, newrng, 0)
myvalue2 = myvalue1 + 1

newrng2 = sdsheet.Range("C" & myvalue1 & ":C" & myvalue2)
Next X

If IsError(Application.Match(stringy2, newrng2, 0)) Then

MsgBox "no match"
Else
MsgBox "match baby"
End If
End If
End Sub
 

Some videos you may like

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Watch MrExcel Video

Forum statistics

Threads
1,122,229
Messages
5,594,944
Members
413,953
Latest member
Arthur1471

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
Top