ComboBox

  • Thread starter Thread starter James Montgomery
  • Start date Start date
J

James Montgomery

Hi,

Can someone help me with populating a ComboBox with say
Text Line 1
Text Line 2
Text Line 3
Than after the user chooses one say 'Text Line 2' have it show his pick in
the Combobox. User would than have to click an 'OK' button to dislplay it in
say in ("D4"). I would want the ability to able to add more 'Text Lines' to
the code myself.

If this is asking to much could someone direct me to a site that might have
such a routine or to someone I could pay for his or her services.
Thanks,
James
 
Link the RowSource (if a form) property of the combobox to the range of data
on the worksheet, and set the Controlsource property to D4 to get the value
stored there.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Hi Bob

The sourse lines of text are not from a row but just lines of text I have
created for the CombeBox. But anyway not sure how to link all this and make
it work
Thanks
 
and yes I'm using a user form

Bob Phillips said:
Link the RowSource (if a form) property of the combobox to the range of data
on the worksheet, and set the Controlsource property to D4 to get the value
stored there.

--

HTH

RP
(remove nothere from the email address if mailing direct)


it
 
Okay, so use

Private Sub Userform_Activate()

With Me.ComboBox1
.AddItem "Text1"
.AddItem "Text2"
'.. etc

.ControlSource = Range("D4").Address(external:=True)

End With

End Sub



--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Thanks Bob
I got it all working with the OK button
Thanks again
James
 
I am having a combobox on a worksheet. I like to fill it in the
worksheet_open() function. In VBA how do i get these methods? - additem,
dataitem, list etc for combobox.

I declared a worksheet wb code in thisworkbook
--------------------
Option Explicit
Public DeptLocRange As Range, AcctRange As Range
Public ws As Worksheet
Private Sub Workbook_Open()
Dim r As Integer
Set ws = Me.Worksheets("Expenses")
With ws
Set DeptLocRange = .Range(.Cells(79, 3), .Cells(86, 6))
Set AcctRange = .Range(.Cells(91, 3), .Cells(92, 16))
r = 2
DeptLocRange.Select
' Worksheets("Expenses").cmbLocation.AddItem ("<select Loc>")
' While Not IsNull(DeptLocRange(r, 1))
' .cmbLocation.AddItem = DeptLocRange(r, 1)
' Wend
' .cmbLocation.ListIndex = 0
' .cmbDepartment.ListIndex = 0
End With
Worksheets("Expenses").cmbLocation.ListIndex = 0
Worksheets("Expenses").cmbDepartment.ListIndex = 0
End Sub

--------------------
commented lines are not working. wb.cmbLocation.listindex won't work. but
the last two lines works. Any help is greatly appreciated.

Thanks
MVMurthy
********************
 
Are you sure it's the commented lines that's causing the trouble.

If you get rid of deptLocRange.select, will it work?

And if you change isNull() to isEmpty() does that help?

If neither of these fixes your problem, maybe you can post some more details of
what happens when you step through the code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top