LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default passing ComboBox to subroutine

On May 8, 8:41 pm, "Tim Williams" <timjwilliams at gmail dot com
wrote:
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
thecomboBoxto the routine. The routine is not able to locate the
comboBoxproperly.
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 thecomboBox?


thanks,
Anand.


It worked !!! Thanks a lot!!!!
 
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
Passing reference to a checkbox to a subroutine. MikeAllgood Excel Programming 4 March 11th 08 06:27 AM
Passing ranges to a subroutine [email protected] Excel Programming 1 March 11th 08 03:15 AM
Passing Module to subroutine SixSigmaGuy[_2_] Excel Programming 2 April 25th 06 10:59 PM
Excel vba - passing a 3-dimensional array to a subroutine [email protected] Excel Programming 5 March 28th 06 07:50 PM
Passing arrays to a subroutine Braden Craig Excel Programming 4 August 17th 03 05:54 PM


All times are GMT +1. The time now is 07:02 PM.

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"