Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Populating Combobox

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!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Populating Combobox

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!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Populating Combobox

Hey Tom,

Thanks for the info. However, I made an error for option 2. It should be
C3-I3 with station 8 becoming J3. It is the same row, not column.

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!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Populating Combobox

You can't populate a combobox with a horizontal range using rowsource. You
will need to loop through the cells and use additem to populate the combobox.

--
regards,
Tom Ogilvy


"WLMPilot" wrote:

Hey Tom,

Thanks for the info. However, I made an error for option 2. It should be
C3-I3 with station 8 becoming J3. It is the same row, not column.

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!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Populating Combobox

I do not know how to do that. I am new to VBA and using comboboxes.

Thanks again!



"Tom Ogilvy" wrote:

You can't populate a combobox with a horizontal range using rowsource. You
will need to loop through the cells and use additem to populate the combobox.

--
regards,
Tom Ogilvy


"WLMPilot" wrote:

Hey Tom,

Thanks for the info. However, I made an error for option 2. It should be
C3-I3 with station 8 becoming J3. It is the same row, not column.

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!



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Populating Combobox

Private Sub Userform_Initialize()
Dim cell as Range
Combobox2.RowSource = ""
Combobox2.Clear
with worksheets("Items")
for each cell in .Range("C3",.Range("C3").End(xltoRight))
Combobox2.AddItem cell.Value
Next
End With
End Sub

--
Regards,
Tom Ogilvy


"WLMPilot" wrote in message
...
I do not know how to do that. I am new to VBA and using comboboxes.

Thanks again!



"Tom Ogilvy" wrote:

You can't populate a combobox with a horizontal range using rowsource.
You
will need to loop through the cells and use additem to populate the
combobox.

--
regards,
Tom Ogilvy


"WLMPilot" wrote:

Hey Tom,

Thanks for the info. However, I made an error for option 2. It should
be
C3-I3 with station 8 becoming J3. It is the same row, not column.

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!



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Populating Combobox

Thanks Tom. However, I am encountering a new problem. Prior to inserting
combobox, I was using textboxes without incident. Now that I inserted the
first set of code (for userform 1), I come up with an error that reads as:

Run-time Error '2147352573 (80020003)':
Could not find the specified object

When I debug, it highlights the indicated line below:

Sub OrderEntry()
Dim iq As New ItemQty ' Userform with combobox
iq.Show <-------HIGHLIGHTS WHEN DEBUGGED
End Sub

I have a subroutine that is activated when the user clicks a command button
"BEGIN ORDER" The code is found below. Within this routine, the routine
"OrderEntry" is called.

'BEGIN NEW ORDER
Private Sub CommandButton2_Click()
Range("C1").Value = ""
Range("F1").Value = ""
Range("C3").Value = ""
Range("D6:H8").Value = ""
Range("A13:B50").ClearContents
Range("G13:H50").Value = ""
Range("B1").Select
Dim st As New STINFO ' Userform: Obtain station# and crew names
st.Show ' Show STINFO userform
Narcotics ' Routine to get narcotic order
OrderEntry ' Routine that shows userform (gets item# and
Qty)
End Sub

As I said before, everything worked fine until I inserted the code for the
combobox.
What would cause this problem?

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!

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Populating Combobox

Your code worked for me in minor testing (just a blank userform named itemqty),
but you may want to try:

Option Explicit
Sub OrderEntry()
Dim iq As itemqty ' Userform with combobox
Set iq = New itemqty
iq.Show '<-------HIGHLIGHTS WHEN DEBUGGED
End Sub

Chip Pearson explains why using "dim xxx as New yyyy" is a bad idea:
http://cpearson.com/excel/variables.htm

look for:
Don't Use The New Keyword In A Dim Statement



WLMPilot wrote:

Thanks Tom. However, I am encountering a new problem. Prior to inserting
combobox, I was using textboxes without incident. Now that I inserted the
first set of code (for userform 1), I come up with an error that reads as:

Run-time Error '2147352573 (80020003)':
Could not find the specified object

When I debug, it highlights the indicated line below:

Sub OrderEntry()
Dim iq As New ItemQty ' Userform with combobox
iq.Show <-------HIGHLIGHTS WHEN DEBUGGED
End Sub

I have a subroutine that is activated when the user clicks a command button
"BEGIN ORDER" The code is found below. Within this routine, the routine
"OrderEntry" is called.

'BEGIN NEW ORDER
Private Sub CommandButton2_Click()
Range("C1").Value = ""
Range("F1").Value = ""
Range("C3").Value = ""
Range("D6:H8").Value = ""
Range("A13:B50").ClearContents
Range("G13:H50").Value = ""
Range("B1").Select
Dim st As New STINFO ' Userform: Obtain station# and crew names
st.Show ' Show STINFO userform
Narcotics ' Routine to get narcotic order
OrderEntry ' Routine that shows userform (gets item# and
Qty)
End Sub

As I said before, everything worked fine until I inserted the code for the
combobox.
What would cause this problem?

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!


--

Dave Peterson
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Populating Combobox

I will try it. However, being new to VBA, do I need to change anything on
how OrderEntry is called? I ask this because the code Option Explicit is
above the "Sub" routine and I was wondering how that works.

Thanks.

"Dave Peterson" wrote:

Your code worked for me in minor testing (just a blank userform named itemqty),
but you may want to try:

Option Explicit
Sub OrderEntry()
Dim iq As itemqty ' Userform with combobox
Set iq = New itemqty
iq.Show '<-------HIGHLIGHTS WHEN DEBUGGED
End Sub

Chip Pearson explains why using "dim xxx as New yyyy" is a bad idea:
http://cpearson.com/excel/variables.htm

look for:
Don't Use The New Keyword In A Dim Statement



WLMPilot wrote:

Thanks Tom. However, I am encountering a new problem. Prior to inserting
combobox, I was using textboxes without incident. Now that I inserted the
first set of code (for userform 1), I come up with an error that reads as:

Run-time Error '2147352573 (80020003)':
Could not find the specified object

When I debug, it highlights the indicated line below:

Sub OrderEntry()
Dim iq As New ItemQty ' Userform with combobox
iq.Show <-------HIGHLIGHTS WHEN DEBUGGED
End Sub

I have a subroutine that is activated when the user clicks a command button
"BEGIN ORDER" The code is found below. Within this routine, the routine
"OrderEntry" is called.

'BEGIN NEW ORDER
Private Sub CommandButton2_Click()
Range("C1").Value = ""
Range("F1").Value = ""
Range("C3").Value = ""
Range("D6:H8").Value = ""
Range("A13:B50").ClearContents
Range("G13:H50").Value = ""
Range("B1").Select
Dim st As New STINFO ' Userform: Obtain station# and crew names
st.Show ' Show STINFO userform
Narcotics ' Routine to get narcotic order
OrderEntry ' Routine that shows userform (gets item# and
Qty)
End Sub

As I said before, everything worked fine until I inserted the code for the
combobox.
What would cause this problem?

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!


--

Dave Peterson

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Populating Combobox

Option explicit will force you to declare any variables that you use. Without
that, your code may have run, but may not have done what you wanted.
(Undeclared variables could be treated as 0, "", ...)

And it'll help you find typos:
xlvalues (EX-ELL-values)
compared with
x1value (EX-One-values)




WLMPilot wrote:

I will try it. However, being new to VBA, do I need to change anything on
how OrderEntry is called? I ask this because the code Option Explicit is
above the "Sub" routine and I was wondering how that works.

Thanks.

"Dave Peterson" wrote:

Your code worked for me in minor testing (just a blank userform named itemqty),
but you may want to try:

Option Explicit
Sub OrderEntry()
Dim iq As itemqty ' Userform with combobox
Set iq = New itemqty
iq.Show '<-------HIGHLIGHTS WHEN DEBUGGED
End Sub

Chip Pearson explains why using "dim xxx as New yyyy" is a bad idea:
http://cpearson.com/excel/variables.htm

look for:
Don't Use The New Keyword In A Dim Statement



WLMPilot wrote:

Thanks Tom. However, I am encountering a new problem. Prior to inserting
combobox, I was using textboxes without incident. Now that I inserted the
first set of code (for userform 1), I come up with an error that reads as:

Run-time Error '2147352573 (80020003)':
Could not find the specified object

When I debug, it highlights the indicated line below:

Sub OrderEntry()
Dim iq As New ItemQty ' Userform with combobox
iq.Show <-------HIGHLIGHTS WHEN DEBUGGED
End Sub

I have a subroutine that is activated when the user clicks a command button
"BEGIN ORDER" The code is found below. Within this routine, the routine
"OrderEntry" is called.

'BEGIN NEW ORDER
Private Sub CommandButton2_Click()
Range("C1").Value = ""
Range("F1").Value = ""
Range("C3").Value = ""
Range("D6:H8").Value = ""
Range("A13:B50").ClearContents
Range("G13:H50").Value = ""
Range("B1").Select
Dim st As New STINFO ' Userform: Obtain station# and crew names
st.Show ' Show STINFO userform
Narcotics ' Routine to get narcotic order
OrderEntry ' Routine that shows userform (gets item# and
Qty)
End Sub

As I said before, everything worked fine until I inserted the code for the
combobox.
What would cause this problem?

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!


--

Dave Peterson


--

Dave Peterson


  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Populating Combobox

And it won't change the way you call the routine.

Ps. You'll want to change this:
Dim st As New STINFO
to
Dim st As STINFO
set st = new stinfo
also.

(But your original code worked ok for me.)

WLMPilot wrote:

I will try it. However, being new to VBA, do I need to change anything on
how OrderEntry is called? I ask this because the code Option Explicit is
above the "Sub" routine and I was wondering how that works.

Thanks.

"Dave Peterson" wrote:

Your code worked for me in minor testing (just a blank userform named itemqty),
but you may want to try:

Option Explicit
Sub OrderEntry()
Dim iq As itemqty ' Userform with combobox
Set iq = New itemqty
iq.Show '<-------HIGHLIGHTS WHEN DEBUGGED
End Sub

Chip Pearson explains why using "dim xxx as New yyyy" is a bad idea:
http://cpearson.com/excel/variables.htm

look for:
Don't Use The New Keyword In A Dim Statement



WLMPilot wrote:

Thanks Tom. However, I am encountering a new problem. Prior to inserting
combobox, I was using textboxes without incident. Now that I inserted the
first set of code (for userform 1), I come up with an error that reads as:

Run-time Error '2147352573 (80020003)':
Could not find the specified object

When I debug, it highlights the indicated line below:

Sub OrderEntry()
Dim iq As New ItemQty ' Userform with combobox
iq.Show <-------HIGHLIGHTS WHEN DEBUGGED
End Sub

I have a subroutine that is activated when the user clicks a command button
"BEGIN ORDER" The code is found below. Within this routine, the routine
"OrderEntry" is called.

'BEGIN NEW ORDER
Private Sub CommandButton2_Click()
Range("C1").Value = ""
Range("F1").Value = ""
Range("C3").Value = ""
Range("D6:H8").Value = ""
Range("A13:B50").ClearContents
Range("G13:H50").Value = ""
Range("B1").Select
Dim st As New STINFO ' Userform: Obtain station# and crew names
st.Show ' Show STINFO userform
Narcotics ' Routine to get narcotic order
OrderEntry ' Routine that shows userform (gets item# and
Qty)
End Sub

As I said before, everything worked fine until I inserted the code for the
combobox.
What would cause this problem?

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!


--

Dave Peterson


--

Dave Peterson
  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default 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!

  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Populating Combobox

Tom,

I found the problem with the line that I indicated as highlighted when
debugged. It was a spelling error with Combobox1 (Combbox1). Once I fixed
that, I got the same runtime error and description with the following line:

Set cellB = cell.Offset(0, 1)

Thanks again and sorry for all the questions. You have been very helpful to
this beginner.

"WLMPilot" wrote:

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!

  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Populating Combobox

I was using the variable cell, but changed it to CellA to make it clearer.
Apparently I didn't change the reference in that line

Set cellA = rng1(ComboBox1.ListIndex + 1)
Set cellB = cell.Offset(0, 1)

should be

Set cellA = rng1(ComboBox1.ListIndex + 1)
Set cellB = cellA.Offset(0, 1)

This will be the cell to the right of the cell in Column A selected in the
combobox if you description and my interpretation match reality.

--
Regards,
Tom Ogilvy





"WLMPilot" wrote in message
...
Tom,

I found the problem with the line that I indicated as highlighted when
debugged. It was a spelling error with Combobox1 (Combbox1). Once I
fixed
that, I got the same runtime error and description with the following
line:

Set cellB = cell.Offset(0, 1)

Thanks again and sorry for all the questions. You have been very helpful
to
this beginner.

"WLMPilot" wrote:

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!



  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Populating Combobox

Everything is working great!!! THANK YOU!!!

Two more short questions:
1) I want the focus to advance from one field (combobox1) to the next field
(quantity) via hitting the ENTER key. Currently, I have to tab to next
field. How can I fix that?

2) Can I place a formula within a Commandbutton_click routine or do I have
to have a separate routine for a formula. I will be calculating the
difference between the quantity ordered and the stock level if qty ordered
stock level.

Thanks

"Tom Ogilvy" wrote:

I was using the variable cell, but changed it to CellA to make it clearer.
Apparently I didn't change the reference in that line

Set cellA = rng1(ComboBox1.ListIndex + 1)
Set cellB = cell.Offset(0, 1)

should be

Set cellA = rng1(ComboBox1.ListIndex + 1)
Set cellB = cellA.Offset(0, 1)

This will be the cell to the right of the cell in Column A selected in the
combobox if you description and my interpretation match reality.

--
Regards,
Tom Ogilvy





"WLMPilot" wrote in message
...
Tom,

I found the problem with the line that I indicated as highlighted when
debugged. It was a spelling error with Combobox1 (Combbox1). Once I
fixed
that, I got the same runtime error and description with the following
line:

Set cellB = cell.Offset(0, 1)

Thanks again and sorry for all the questions. You have been very helpful
to
this beginner.

"WLMPilot" wrote:

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!






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Populating a combobox WLMPilot Excel Programming 1 March 12th 07 08:07 PM
ComboBox populating problem Werner[_33_] Excel Programming 1 July 29th 05 10:00 PM
Populating a ComboBox DirInfo Excel Programming 1 March 17th 05 10:03 PM
Populating combobox/listbox Torstein S. Johnsen[_2_] Excel Programming 1 May 13th 04 09:26 AM
Populating ComboBox Methods Todd Huttenstine[_2_] Excel Programming 8 January 19th 04 12:14 AM


All times are GMT +1. The time now is 04:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"