Autofill Userform by Matching Previous Data

jarredhoo

New Member
Joined
Apr 21, 2011
Messages
4
Hi There,

I am very new at excel programming, and I'm attempting to create my first userform. I'm trying to see if I can save time on filling out the form by having it autofill if the information already exists on the spreadsheet.

Example: Each person has a unique ID, if I type their user ID into the corresponding userform text box, and that ID already exists on the spreadsheet, I want to autofill their name, address, etc. similar to an online form autofill function. The spreadsheet will continue to grow as I go, therefore I need a dynamic range, referencing all of the information above the new entry as a potential match to the ID.

I'm not sure how to match the user ID, or have it return their corresponding name to the name text box. Here is the code I've got so far:

Code:
Private Sub txtCallerID_AfterUpdate()
 
Range("A1").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
ActiveCell = txtCallerID.Value
 
Dim MyRange As Range
Set MyRange = Range(Selection, Selection.End(xlUp))
 
VL = WorksheetFunction.Match _
(txtCallerID.Value, [MyRange], 0)
If NotFound Then
txtName.Value = ""
Exit Sub
Else
txtName.Value = "Name??"
End If
 
End Sub

Thank you in anticipation of your help!

Jarred
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,224,504
Messages
6,179,144
Members
452,891
Latest member
JUSTOUTOFMYREACH

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