Search code examples
excelvbareferenceuserformxlookup

How can I reference the value of a textbox in a UserForm in VBA?


I'm running an xlookup function that i have had previously work on just standard cells, but now i am trying to get it to work from my userform.

Here is my code:

Sub bizlookup()
Worksheets("Input").Range("company").Select
ActiveCell = Application.XLookup(Worksheets("Input").Range("phone"), Worksheets("MASTER").Range("S:S"), Worksheets("MASTER").Range("U:U"))
End Sub

I want to replace the "(Worksheets("Input").Range("phone")" with the value of a TextBox on a userform. How would I reference the value in the textbox?


Solution

  • Replace this with the names of your userform and textbox.

    Worksheets("Input").Range("Phone").Value = UserFormName.TextBoxName.Value