PDA

View Full Version : Solved: Return a value into a textbox when selecting a worksheet name from a combobox



Rlb53
08-27-2011, 05:25 PM
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



TextBox1.Value = Sheets(Material_On_Hand.Value).Range("f2").Value



How may I display the desired information within the textbox as the selected worksheet is changed in the combobox.

Thank you for your assistance.

Rlb53
08-27-2011, 06:54 PM
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 !

frank_m
08-27-2011, 11:43 PM
Assuming each combobox change activates a different sheet, you probably could use the sheets activation event.
Private Sub Worksheet_Activate()
UserForm1.TextBox1.Value = Range("F2").Value
End Sub or couldn't you just add --> Me.TextBox1.Value = Range("F2").Value, after the combobox code that selects the sheet?