Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a very basic problem

Status
Not open for further replies.

ninash

Technical User
Jul 6, 2001
163
GB
Forgive me if this is too simple

I am designing a Excel User Form that contains a combo box

Firstly I want to populate the combo box with values of my own that will remain static

Secondly I want to know how I access the chosen value in the combo box to enable the remaining part of my macro to function.

This is something I have never done before and need help badly

Thanks in advance
 
Hi, try something like this. It's dynamic, so if you add some more data, it will automatically fill it in.

Private Sub UserForm_Initialize()

Dim Row as Integer
Dim Data as Object
Dim I as Integer
Set Data = Sheets("Sheet1").Cells


Row = 5
While Not IsEmpty(Data(Row, 1))
ComboBox.AddItem (Data(Row, 1))

I = I + 1
Row = Row + 1
Wend
End Sub
 
Hi

You can use the Change event to access the chosen value of the combobox, try this,

Private Sub ComboBox1_Change()

Dim cboValue As String

cboValue = Me.ComboBox1

With Me
.Label1.Caption = cboValue
End With
End Sub

The label caption will change when the value of the combo box changes.

Hope this helps.

Regards
LSTAN
 
Thanks I will populate it with your code , but what about reading the values in the combo to allow the rest of my macro to complete it's calculations
 
Hi,
MyValue = Userform1.Combobox1.Text

:) Skip,
metzgsk@voughtaircraft.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top