Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm having quite a few combo boxes in the excel gui those I need to
fill in with data in same fashion. Hence I created a subroutine to fill in the combo box. My idea is to pass the name of the combo box to a subroutine and then the subroutine will fill in the data appropriately for the said combo box. This I can then repeat for other combo boxes. However, I'm not yet successful doing so. Any help in how I can achieve this would be appreciated. Thanks, Anand. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Why not show what you have so far ?
Tim "Anand" wrote in message ... I'm having quite a few combo boxes in the excel gui those I need to fill in with data in same fashion. Hence I created a subroutine to fill in the combo box. My idea is to pass the name of the combo box to a subroutine and then the subroutine will fill in the data appropriately for the said combo box. This I can then repeat for other combo boxes. However, I'm not yet successful doing so. Any help in how I can achieve this would be appreciated. Thanks, Anand. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Anand
I agree with Tim it would be good to see your code so far as it is a lot easier to figure out how to help when you can see what you are trying to do. However it sounds to me like you are trying to fill all the comboboxes on your form one after an other??? The code below is one way of doing just that, to test the code set up a userform with 4 comboboxes and a button leaving all the names as the default then paste the code to the userform module. Then fill out some data in the active sheet, column A will fill combobox1 - column B will fill combobox2 etc. I hope this gives you some idea of the method used. Option Explicit Dim Ctrl As Control Dim i As Integer Dim c As Integer Private Sub CommandButton1_Click() For i = 1 To 4 '4 is the number of comboboxes Set Ctrl = UserForm1.Controls("ComboBox" & i) For c = 1 To Cells(65536, i).End(xlUp).Row Ctrl.AddItem (Cells(c, i)) Next c Next i Set Ctrl = Nothing End Sub I hope this helps Steve |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On May 7, 5:16 am, Incidental wrote:
Hi Anand I agree with Tim it would be good to see your code so far as it is a lot easier to figure out how to help when you can see what you are trying to do. However it sounds to me like you are trying to fill all the comboboxes on your form one after an other??? The code below is one way of doing just that, to test the code set up a userform with 4 comboboxes and a button leaving all the names as the default then paste the code to the userform module. Then fill out some data in the active sheet, column A will fill combobox1 - column B will fill combobox2 etc. I hope this gives you some idea of the method used. Option Explicit Dim Ctrl As Control Dim i As Integer Dim c As Integer Private Sub CommandButton1_Click() For i = 1 To 4 '4 is the number of comboboxes Set Ctrl = UserForm1.Controls("ComboBox" & i) For c = 1 To Cells(65536, i).End(xlUp).Row Ctrl.AddItem (Cells(c, i)) Next c Next i Set Ctrl = Nothing End Sub I hope this helps Steve Hi, Here is what I'm trying to do: Public Sub selectID(cboBox) ' cboBox should be the combo box handle Dim IDClm As Range Dim LastRow As Long Dim IDStr As String Set IDClm = shtIDLists.Range(shtIDLists.Cells(4, 5), shtIDLists.Cells(5000, 5)) LastRow = getLastUsedRow(IDClm) ' This is working subroutine gives last used row For lrow = 4 To LastRow If Not IsEmpty(shtIDLists.Cells(lrow, 5)) Then IDStr = shtIDLists.Cells(lrow, 5).Value cboBox.AddItem IDStr End If Next lrow End Sub I want to call this subroutine from different forms: Form1 - selectID(comboBox1); Form2 - selectID(comboBox2); How can I achieve this? thanks, Anand. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
From within a form you should just be able to do:
selectID Me.ComboBoxName That doesn't work for you ? Tim "Anand" wrote in message ... On May 7, 5:16 am, Incidental wrote: Hi Anand I agree with Tim it would be good to see your code so far as it is a lot easier to figure out how to help when you can see what you are trying to do. However it sounds to me like you are trying to fill all the comboboxes on your form one after an other??? The code below is one way of doing just that, to test the code set up a userform with 4 comboboxes and a button leaving all the names as the default then paste the code to the userform module. Then fill out some data in the active sheet, column A will fill combobox1 - column B will fill combobox2 etc. I hope this gives you some idea of the method used. Option Explicit Dim Ctrl As Control Dim i As Integer Dim c As Integer Private Sub CommandButton1_Click() For i = 1 To 4 '4 is the number of comboboxes Set Ctrl = UserForm1.Controls("ComboBox" & i) For c = 1 To Cells(65536, i).End(xlUp).Row Ctrl.AddItem (Cells(c, i)) Next c Next i Set Ctrl = Nothing End Sub I hope this helps Steve Hi, Here is what I'm trying to do: Public Sub selectID(cboBox) ' cboBox should be the combo box handle Dim IDClm As Range Dim LastRow As Long Dim IDStr As String Set IDClm = shtIDLists.Range(shtIDLists.Cells(4, 5), shtIDLists.Cells(5000, 5)) LastRow = getLastUsedRow(IDClm) ' This is working subroutine gives last used row For lrow = 4 To LastRow If Not IsEmpty(shtIDLists.Cells(lrow, 5)) Then IDStr = shtIDLists.Cells(lrow, 5).Value cboBox.AddItem IDStr End If Next lrow End Sub I want to call this subroutine from different forms: Form1 - selectID(comboBox1); Form2 - selectID(comboBox2); How can I achieve this? thanks, Anand. |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On May 7, 7:38 pm, "Tim Williams" <timjwilliams at gmail dot com
wrote: From within a form you should just be able to do: selectID Me.ComboBoxName That doesn't work for you ? Tim "Anand" wrote in message ... On May 7, 5:16 am, Incidental wrote: Hi Anand I agree with Tim it would be good to see your code so far as it is a lot easier to figure out how to help when you can see what you are trying to do. However it sounds to me like you are trying to fill all the comboboxes on your form one after an other??? The code below is one way of doing just that, to test the code set up a userform with 4 comboboxes and a button leaving all the names as the default then paste the code to the userform module. Then fill out some data in the active sheet, column A will fill combobox1 - column B will fill combobox2 etc. I hope this gives you some idea of the method used. Option Explicit Dim Ctrl As Control Dim i As Integer Dim c As Integer Private Sub CommandButton1_Click() For i = 1 To 4 '4 is the number of comboboxes Set Ctrl = UserForm1.Controls("ComboBox" & i) For c = 1 To Cells(65536, i).End(xlUp).Row Ctrl.AddItem (Cells(c, i)) Next c Next i Set Ctrl = Nothing End Sub I hope this helps Steve Hi, Here is what I'm trying to do: Public Sub selectID(cboBox) ' cboBox should be the combo box handle Dim IDClm As Range Dim LastRow As Long Dim IDStr As String Set IDClm = shtIDLists.Range(shtIDLists.Cells(4, 5), shtIDLists.Cells(5000, 5)) LastRow = getLastUsedRow(IDClm) ' This is working subroutine gives last used row For lrow = 4 To LastRow If Not IsEmpty(shtIDLists.Cells(lrow, 5)) Then IDStr = shtIDLists.Cells(lrow, 5).Value cboBox.AddItem IDStr End If Next lrow End Sub I want to call this subroutine from different forms: Form1 - selectID(comboBox1); Form2 - selectID(comboBox2); How can I achieve this? thanks, Anand. Well, I tried but it does not work. I guess, it is related to passing the comboBox to the routine. The routine is not able to locate the comboBox properly. The routine is located in separate module. This routine is supposed to work with different forms as well. Do I need to pass the Form handle as well? My question is the routine gets the name of the box as a string. How would it figure out where the combo box is located and what is the actual name(handle) to the comboBox? thanks, Anand. |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Don't pass the combo as a string - pass an object reference.
Public Sub selectID(cboBox as object) Tim "Anand" wrote in message ... On May 7, 7:38 pm, "Tim Williams" <timjwilliams at gmail dot com wrote: From within a form you should just be able to do: selectID Me.ComboBoxName That doesn't work for you ? Tim "Anand" wrote in message ... On May 7, 5:16 am, Incidental wrote: Hi Anand I agree with Tim it would be good to see your code so far as it is a lot easier to figure out how to help when you can see what you are trying to do. However it sounds to me like you are trying to fill all the comboboxes on your form one after an other??? The code below is one way of doing just that, to test the code set up a userform with 4 comboboxes and a button leaving all the names as the default then paste the code to the userform module. Then fill out some data in the active sheet, column A will fill combobox1 - column B will fill combobox2 etc. I hope this gives you some idea of the method used. Option Explicit Dim Ctrl As Control Dim i As Integer Dim c As Integer Private Sub CommandButton1_Click() For i = 1 To 4 '4 is the number of comboboxes Set Ctrl = UserForm1.Controls("ComboBox" & i) For c = 1 To Cells(65536, i).End(xlUp).Row Ctrl.AddItem (Cells(c, i)) Next c Next i Set Ctrl = Nothing End Sub I hope this helps Steve Hi, Here is what I'm trying to do: Public Sub selectID(cboBox) ' cboBox should be the combo box handle Dim IDClm As Range Dim LastRow As Long Dim IDStr As String Set IDClm = shtIDLists.Range(shtIDLists.Cells(4, 5), shtIDLists.Cells(5000, 5)) LastRow = getLastUsedRow(IDClm) ' This is working subroutine gives last used row For lrow = 4 To LastRow If Not IsEmpty(shtIDLists.Cells(lrow, 5)) Then IDStr = shtIDLists.Cells(lrow, 5).Value cboBox.AddItem IDStr End If Next lrow End Sub I want to call this subroutine from different forms: Form1 - selectID(comboBox1); Form2 - selectID(comboBox2); How can I achieve this? thanks, Anand. Well, I tried but it does not work. I guess, it is related to passing the comboBox to the routine. The routine is not able to locate the comboBox properly. The routine is located in separate module. This routine is supposed to work with different forms as well. Do I need to pass the Form handle as well? My question is the routine gets the name of the box as a string. How would it figure out where the combo box is located and what is the actual name(handle) to the comboBox? thanks, Anand. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Passing reference to a checkbox to a subroutine. | Excel Programming | |||
Passing ranges to a subroutine | Excel Programming | |||
Passing Module to subroutine | Excel Programming | |||
Excel vba - passing a 3-dimensional array to a subroutine | Excel Programming | |||
Passing arrays to a subroutine | Excel Programming |