-
Solved: Return a value into a textbox when selecting a worksheet name from a combobox
I have a Userform created.
Within this userform is a ComboBox.
The Combobox is assigned to a list of worksheets.
I also have a textbox within the same userform.
I would like to select a worksheet within the combobox and have information from a specified cell in the selected worksheet display in the textbox. (the cell with the desired information is in the same location within each worksheet, "F2")
At the moment I have the combobox named as "Material_On_Hand".
The information provided from the Row Source is accurate.
The current code I have setup within the textbox is
[vba]
TextBox1.Value = Sheets(Material_On_Hand.Value).Range("f2").Value
[/vba]
How may I display the desired information within the textbox as the selected worksheet is changed in the combobox.
Thank you for your assistance.
-
Got it figured out.
the code returned the value sought, I just had to activate the command by calling it through an attached command button.
However... if anyone knows how I may execute the command upon selection of a different worksheet without having to execute it... I'd like to know.
Thank you for being here !
-
Assuming each combobox change activates a different sheet, you probably could use the sheets activation event.
[vba]Private Sub Worksheet_Activate()
UserForm1.TextBox1.Value = Range("F2").Value
End Sub[/vba] or couldn't you just add --> Me.TextBox1.Value = Range("F2").Value, after the combobox code that selects the sheet?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules