Finding Customers with the same name

Dan Swartz

Board Regular
Joined
Apr 17, 2020
Messages
53
Office Version
  1. 365
Platform
  1. Windows
I have a userform for pulling a customer's information. it works great. But if I have two or more customers with the same name. It only finds the first name. I live in a community of Amish. It's not uncommon to have 5 - 10 customers with the same name.

I don't even know where to start.

Is there a way to search for a name, display all customers with the same name, but show their address so i would know which customer is the correct one and then be able to choose that customer?

This is my code for the current Customer Form.

VBA Code:
Private Sub FindCust_Click()
    
  Dim f As Range
  
  If CustomerName.Value = "" Then
    MsgBox "Please enter a customer name"
    CustomerName.SetFocus
    Exit Sub
  End If
  
  Set f = Sheet2.Range("A:A").Find(CustomerName.Value, , xlValues, xlWhole, , , False)
  If Not f Is Nothing Then
    Address1.Text = Sheet2.Cells(f.Row, 2).Value
    Address2.Text = Sheet2.Cells(f.Row, 3).Value
    City.Text = Sheet2.Cells(f.Row, 4).Value
    State.Text = Sheet2.Cells(f.Row, 5).Value
    Zip.Text = Sheet2.Cells(f.Row, 6).Value
    Email.Text = Sheet2.Cells(f.Row, 7).Value
  Else
    MsgBox ("Customer does not exist"), vbOKOnly
    CustomerName.SetFocus
  End If
End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I have a userform for pulling a customer's information. it works great. But if I have two or more customers with the same name. It only finds the first name. I live in a community of Amish. It's not uncommon to have 5 - 10 customers with the same name.

I don't even know where to start.

Is there a way to search for a name, display all customers with the same name, but show their address so i would know which customer is the correct one and then be able to choose that customer?

This is my code for the current Customer Form.

VBA Code:
Private Sub FindCust_Click()
   
  Dim f As Range
 
  If CustomerName.Value = "" Then
    MsgBox "Please enter a customer name"
    CustomerName.SetFocus
    Exit Sub
  End If
 
  Set f = Sheet2.Range("A:A").Find(CustomerName.Value, , xlValues, xlWhole, , , False)
  If Not f Is Nothing Then
    Address1.Text = Sheet2.Cells(f.Row, 2).Value
    Address2.Text = Sheet2.Cells(f.Row, 3).Value
    City.Text = Sheet2.Cells(f.Row, 4).Value
    State.Text = Sheet2.Cells(f.Row, 5).Value
    Zip.Text = Sheet2.Cells(f.Row, 6).Value
    Email.Text = Sheet2.Cells(f.Row, 7).Value
  Else
    MsgBox ("Customer does not exist"), vbOKOnly
    CustomerName.SetFocus
  End If
End Sub
If there are two or more of the same name, where should those "extra" names be placed, under or alongside the first one that is found?
 
Upvote 0
At this point, I have lots of options. I'm just in the middle of creating it. I would prefer them to show up in a popup box and after I choose the correct customer, it disappears and fills out my form. but that may be too fancy. If it needs to be a listbox that always shows. that's ok. Attached is what my Userform looks like.
 

Attachments

  • Customer Info Box.png
    Customer Info Box.png
    9.5 KB · Views: 5
Upvote 0
Well, if that is your form, you would need some kind of up/down button system so you could move through the multiple names when there are multiple names.
 
Upvote 0
Well, if that is your form, you would need some kind of up/down button system so you could move through the multiple names when there are multiple names.
I'm open to any suggestions you would have. I'm very new to VBA. The people using this will be computer illiterate. they will struggle with complexity. So I want to make it easy to use. Again. I can modify the form for whatever is best. Not stuck on that. just what I created to this point
 
Upvote 0
@Dan Swartz
I just want to suggest something:
I hope you have a column for a unique ID for each customer in your data table. If not, create one. It should be something like this:
Book1
ABC
1CUSTOMER IDNAMEADDRESS
2A000001Helenadress1
3A000002Davidadress2
4A000003Davidadress3
5A000004Ronaldadress4
6A000005Kimberlyadress5
7A000006Mariaadress6
Sheet2

Please ensure that the number of digits will be sufficient to accommodate all future customers.
 
Upvote 1
@Dan Swartz
I just want to suggest something:
I hope you have a column for a unique ID for each customer in your data table. If not, create one. It should be something like this:
Book1
ABC
1CUSTOMER IDNAMEADDRESS
2A000001Helenadress1
3A000002Davidadress2
4A000003Davidadress3
5A000004Ronaldadress4
6A000005Kimberlyadress5
7A000006Mariaadress6
Sheet2

Please ensure that the number of digits will be sufficient to accommodate all future customers.
I have everything in columns like that. but I do not have a Customer ID. I don't necessarily need on. but if it's better to use in this case. then I can add that.
 
Upvote 0
I have everything in columns like that. but I do not have a Customer ID. I don't necessarily need on. but if it's better to use in this case. then I can add that.
Having a unique identifier for each record is a basic requirement in setting up a proper database. It makes data management and coding much easier. For example, after editing a record in the user form, you only need to identify the customer ID to update the correct record.
So, yeah, it's better to have one.
 
Upvote 1
Having a unique identifier for each record is a basic requirement in setting up a proper database. It makes data management and coding much easier. For example, after editing a record in the user form, you only need to identify the customer ID to update the correct record.
So, yeah, it's better to have one.
Thank You. Already in the process of adding! thank you for your suggestion!!!!
 
Upvote 0
Could you please upload a sample workbook (without sensitive data) to a file-sharing site like Dropbox.com or Google Drive, and then share the link here? Also, ensure that the link is accessible to anyone.
 
Upvote 0

Forum statistics

Threads
1,215,168
Messages
6,123,402
Members
449,098
Latest member
ArturS75

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