Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Is there a way to change the controlsource property for a textbox in VBA.

0

I need to change the controlsource for a textbox in a userform depending on the username. Is there a way to do this. I tried Me.TextBox1.ControlSource = lpoCust.

LpoCust is a named cell

Answer
Discuss

Answers

0
Selected Answer

Bjotr

Just put quotation marks round the named range (within the Userform Initialize code) like this:

Me.TextBox1.ControlSource = "LpoCust"

or if you want something from another sheet, use something like:

Me.TextBox1.ControlSource = "Sheet2!E1"
Discuss

Discussion

Yes, thank You. I used the brackets, and that won't work. 
Thank You
Bjotr (rep: 6) Jun 2, '22 at 6:07 pm
I didn't suggest brackets (parantheses) but quotation marks. That seems to work for me. Are you sure LpoCust contains a value? 
John_Ru (rep: 6142) Jun 2, '22 at 6:58 pm
If you struggle, please add an Excel file to your question and I'll look tomorrow 
John_Ru (rep: 6142) Jun 2, '22 at 6:59 pm
This works like expected when using quotation marks as You suggested. In the first place I used brackets, and that won't work. Now it works nice.
Bjotr (rep: 6) Jun 3, '22 at 4:48 am
That's good (and sorry for my confusion). .Thanks for selecting my answer, Bjotr 
John_Ru (rep: 6142) Jun 3, '22 at 5:28 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login