View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default adding test and cell address to combo box.

I would just add a hidden column and store the address there. Then you can
you can retrieve the information when you need it.


Private Sub UserForm_Initialize()
Dim MyRange As Range
Set MyRange = Sheets("sheet1").Range("k1:z1,k21:z21")
With ComboBox3
.ColumnCount = 2
.ColumnWidths = ";-1"
For Each c In MyRange
If c < "" Then
.AddItem c.Value
.List(.ListCount - 1, 1) = c.Address
End If
Next
End With
End Sub

' some demo code showing how to get at it

Private Sub ComboBox3_Click()
With ComboBox3
MsgBox .Value & " address: " & .List(.ListIndex, 1)
End With
End Sub

This is form a userform, but a similar approach would work on a combobox on
the worksheet (from the controls toolbox toolbar)

--
Regards,
Tom Ogilvy


"Kevin" wrote:

ok, I have this code below that populates ComboBox3 with the text in MyRange.
What I would like to do is record the address of the cell somwhere for
reference once a value is selected in combobox3.

EX. If ComboBox3 is populated and I select the text that is on cell K1 I
need the address K1 recoreded somewhere so that I can populate a second combo
box with range k3:k18. Or if the text for L2 is selected I need a
second combo box with L3:L18 and so forth.

==========================================
Dim MyRange As Range
Set MyRange = Sheets("sheet1").Range("k1:z1,k21:z21")
For Each C In MyRange
If C = "" Then
GoTo 10
Else
ComboBox3.AddItem C.Value
End If
10: Next
==========================================