comparing text

bensonsearch

Well-known Member
Joined
May 26, 2011
Messages
844
Hi,
I have the following code that will look up the excel sheet to see if customer name exsists. however this way must be an exact match ; ie joe citizen must be joe citizen but if its joeseph citizen it will let it through. i want it to find that.

any way to fix this?

Code:
Dim count As Integer
Dim vlook As String
Dim value As Variant
Dim address As Variant
count = Range("A2").CurrentRegion.Rows.count
count = count + 1
vlook = TextBox1.Text
value = Application.VLookup(vlook, Worksheets("Sheet1").Range("A2:G" & count), 1, False)
If IsError(value) Then

ThisWorkbook.Sheets("Sheet1").Range("A" & count).value = TextBox1.Text
ThisWorkbook.Sheets("Sheet1").Range("B" & count).value = TextBox2.Text
ThisWorkbook.Sheets("Sheet1").Range("C" & count).value = TextBox3.Text
ThisWorkbook.Sheets("Sheet1").Range("D" & count).value = TextBox4.Text
ThisWorkbook.Sheets("Sheet1").Range("E" & count).value = TextBox5.Text
ThisWorkbook.Sheets("Sheet1").Range("F" & count).value = TextBox6.Text
ThisWorkbook.Sheets("Sheet1").Range("G" & count).value = TextBox7.Text
Else
address = Application.VLookup(vlook, Worksheets("Sheet1").Range("A2:G" & count), 2, False)
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Customer, " & value & " " & address & " " & "already exsists, do you wish to add?"    ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2    ' Define buttons.
Title = "Error"    ' Define title.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then    ' User chose Yes.
     ' Perform some action.
 
ThisWorkbook.Sheets("Sheet1").Range("A" & count).value = TextBox1.Text
ThisWorkbook.Sheets("Sheet1").Range("B" & count).value = TextBox2.Text
ThisWorkbook.Sheets("Sheet1").Range("C" & count).value = TextBox3.Text
ThisWorkbook.Sheets("Sheet1").Range("D" & count).value = TextBox4.Text
ThisWorkbook.Sheets("Sheet1").Range("E" & count).value = TextBox5.Text
ThisWorkbook.Sheets("Sheet1").Range("F" & count).value = TextBox6.Text
ThisWorkbook.Sheets("Sheet1").Range("G" & count).value = TextBox7.Text
Else    ' User chose No.
   'Perform some action.
Exit Sub
End If
End If
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,224,543
Messages
6,179,429
Members
452,914
Latest member
echoix

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