Prefill Exel Userform with data from a worksheet

I have a spreadsheet with multiple customers. Customer information (i.e. name, address) is entered on the last worksheet. A userform is used to fill in an invoice worksheet. How can I prefill the userform with customer information when typing the customer name?
waynerayAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
do you mean to populate the User Form with data from Worksheet?

if yes, then see if this is good for you?

Private Sub UserForm_Activate()
    Dim r As Integer
    r = ActiveCell.row
    txtName.Text = ActiveSheet.Cells(r, 1)
    txtAddress.Text = ActiveSheet.Cells(r, 2)
End Sub

Open in new window

29086195.xlsm
0
waynerayAuthor Commented:
Excellent. Thanks. What I needed.
0
Roy CoxGroup Finance ManagerCommented:
I would use a ComboBox to select the name. See the example - select a name, the rest of the data auto fills the TextBoxes.

The code is dynamic to you can add columns of data and TextBoxes as required, simply name the TextBoxes TextBox1, TextBox2, etc.
ComboBox-Lookup.xlsm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Fabrice LambertFabrice LambertCommented:
I would use the userForm_initialize() event instead of UserForm_Activate(), as the later may fire more than once (eventually overwriting data) wich may not be the behavior you expect.

Also, I do not advice using objects such as ActiveWorkbook, ActiveSheet, ActiveCell ect ... as these objects are user dependant and by nature chaotic. As a developper, you don't want to use chaotic objects (Ask yourself: What will happen if the user open or alt-tab to another workbook ?).
Prefer referencing precisely the objects you intend to use:
Dim wb As Excel.Workbook
Set wb = ThisWorkbook    '// ref the workbook holding VBA code

Dim ws As Excel.Worksheet
Set ws = wb.Worksheets(1)    '// ref the 1st worksheet of the workbook holding the code

Dim rng As Excel.Range
Set rng = ws.Range("B8")    '// ref the B8 cell of the 1st worksheet

Open in new window

0
waynerayAuthor Commented:
Thanks Experts
0
Roy CoxGroup Finance ManagerCommented:
Pleased to help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.