Populating Combobox
Tom,
Thanks for all your help!!! Most everything is working but I am coming up
with an error with the following code you provided that obtains the item
description. The error is a Runtime Error 424 - Object Required. I have
indicated the line that the error occurs in. NOTE: Please read below the
code for another question. The code is:
Private Sub ComboBox1_Click()
Dim rng1 As Range, cellA As Range
Dim cellB As Range
With Worksheets("Items")
Set rng1 = .Range(Combbox1.RowSource) <---HILGIHTED WHEN DEBUGGED
End With
Set cellA = rng1(ComboBox1.ListIndex + 1)
Set cellB = cell.Offset(0, 1)
' use cellB to get the description
End Sub
My question at this point (when error free) is that I assume cellB is a
variable and that I can assign (insert) it into a cell within another routine?
Thanks!!
"Tom Ogilvy" wrote:
Put an initialize event in each form using this code:
Private Sub Userform_Initialize()
Dim rng1 as Range
with Worksheets("Items")
set rng1 = .Range(.Range("A3"),.Range("A3").End(xldown))
End with
Combobox1.RowSource = rng1.Address(0,0,xlA1,True)
End with
In Userform1, use the above code
In userform2, change the A3 to C3 in both instances
in Userform3, change the A3 to M3 in both instances.
In userform1 to get the description
Private Sub Combobox1_Click()
Dim rng1 as Range, cellA as Range
Dim cellB as Range
With worksheets("Items")
set rng1 = .Range(Combbox1.Rowsource)
end with
set cellA = rng1(Combobox1.ListIndex + 1)
set cellB = cell.offset(0,1)
' use cellB to get the description
end Sub
--
Regards,
Tom Ogilvy
End Sub
"WLMPilot" wrote:
I have three userforms, each with a combobox that I need to populate with
items from the same worksheet. Also each list that populates each combobox
has the possibility to increase is number of items. The name of the
worksheet the holds all the data is "Items"
1) This is the largest and can probably use a feature I have seen where the
command scrolls up to the last empty row. I need to pull item number and
item description from "Items". Starting cell for each is A3 and B3
respectfully. Ending cell is unknown due to the possibility of adding new
items. However, I will not enter any data having to do with anything else
past the end of the list. I only need to populate with the item number but
need to be able to place the item number and corresponding item description
in the appropriate cells (already have code to place data in cell).
2) Currently, I have station numbers 1-7 in C3-C9. This may be added to if
a new EMS station is built, ie station 8 would be in C10. How do you
populate a combobox using same row. NOTE: I have data to the right of this
list that pertains to another combobox (see #3).
3) Currently I have a list of the ambulance numbers (M1, M2, M4, M7, etc) in
a list starting with M3 and listing down the sheet. I am not sure if you can
pinpoint that column and still do a command that locates the last empty cell
in that column or not. For this example, let's say M3-M20 contains each unit
number, with the possibility of adding more.
Thanks!
|