Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default ComboBox Drop Down List

I have 14 Combo Boxes on my Excel form that I want to populate with "Yes" and
"No" with the initialize event. The only way I know how to do it is to use
the following code for each ComboBox.

With ComboBox#
.AddItem "Yes"
.AddItem "No"
End With

Is there simpler code to accomplish this?

Thank you
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default ComboBox Drop Down List

You can set up a pair of cells in a column in your workbook and give them a
name such as YNList and then your code can read:

Me.ComboBox#.RowSource="YNList"

(of course you can skip the Me. if you want).

The named list can be on any sheet in the workbook, even a hidden sheet.

"Johnny" wrote:

I have 14 Combo Boxes on my Excel form that I want to populate with "Yes" and
"No" with the initialize event. The only way I know how to do it is to use
the following code for each ComboBox.

With ComboBox#
.AddItem "Yes"
.AddItem "No"
End With

Is there simpler code to accomplish this?

Thank you

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default ComboBox Drop Down List

If your comboboxes are named nicely:

Dim iCtr As Long
For iCtr = 1 To 14
With Me.Controls("Combobox" & iCtr)
.AddItem "Yes"
.AddItem "No"
End With
Next iCtr



Johnny wrote:

I have 14 Combo Boxes on my Excel form that I want to populate with "Yes" and
"No" with the initialize event. The only way I know how to do it is to use
the following code for each ComboBox.

With ComboBox#
.AddItem "Yes"
.AddItem "No"
End With

Is there simpler code to accomplish this?

Thank you


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default ComboBox Drop Down List

Another way perhaps.

Private Sub UserForm_Initialize()
Dim ctl As Control
Dim CtrlType As String

For Each ctl In UserForm1.Controls

CtrlType = TypeName(ctl)

If CtrlType = "ComboBox" Then

ctl.AddItem "Yes"
ctl.AddItem "No"
ctl.ListIndex = 0

End If
Next ctl
End Sub
--
jb


"Johnny" wrote:

I have 14 Combo Boxes on my Excel form that I want to populate with "Yes" and
"No" with the initialize event. The only way I know how to do it is to use
the following code for each ComboBox.

With ComboBox#
.AddItem "Yes"
.AddItem "No"
End With

Is there simpler code to accomplish this?

Thank you

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default ComboBox Drop Down List

'A one time loop will do

'if you are using a user form...
Dim intTemp As Integer
For intTemp = 1 To 14
Me.Controls("Combobox" & intTemp).AddItem "Yes"
Me.Controls("Combobox" & intTemp).AddItem "No"
Next

'If the comboboxes are in Activesheet
Dim intTemp As Integer
For intTemp = 1 To 14
ActiveSheet.OLEObjects("Combobox" & intTemp).Object.AddItem "Yes"
ActiveSheet.OLEObjects("Combobox" & intTemp).Object.AddItem "No"
Next

If this post helps click Yes
---------------
Jacob Skaria


"Johnny" wrote:

I have 14 Combo Boxes on my Excel form that I want to populate with "Yes" and
"No" with the initialize event. The only way I know how to do it is to use
the following code for each ComboBox.

With ComboBox#
.AddItem "Yes"
.AddItem "No"
End With

Is there simpler code to accomplish this?

Thank you



  #6   Report Post  
Posted to microsoft.public.excel.programming
r r is offline
external usenet poster
 
Posts: 125
Default ComboBox Drop Down List

assuming the names of the combo as:
ComboBox1, ComboBox2 ... ComboBox14

'in worksheet module
Sub Inizialize_Combo()
Dim oC As Object
For Each oC In ActiveSheet.OLEObjects
AddList oC
Next
End Sub

'in userform module
Private Sub UserForm_Initialize()
Dim oC As Object
For Each oC In Me.Controls
AddList oC
Next
End Sub

'in standard module
Sub AddList(cnt As Object)
Dim v
Dim RE As Object

Set RE = CreateObject("vbscript.regexp")
RE.ignorecase = True
RE.Pattern = "^combobox([1-9]|1[0-4])$"
v = Array("Yes", "No")
If RE.test(cnt.Name) Then
If TypeName(cnt) = "ComboBox" Then
cnt.List = v
ElseIf TypeName(cnt) = "OLEObject" Then
cnt.Object.List = v
End If
End If
End Sub

regards
r

Il mio ultimo lavoro ...
http://excelvba.altervista.org/blog/...ternative.html


"Johnny" wrote:

I have 14 Combo Boxes on my Excel form that I want to populate with "Yes" and
"No" with the initialize event. The only way I know how to do it is to use
the following code for each ComboBox.

With ComboBox#
.AddItem "Yes"
.AddItem "No"
End With

Is there simpler code to accomplish this?

Thank you

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
ComboBox drop list when clicked on??????????? Tdp Excel Discussion (Misc queries) 6 November 13th 08 05:55 PM
Combobox List Drop on Entry Daniel A.[_2_] Excel Programming 3 December 19th 07 01:35 PM
multiple select from the drop down list in excel. list in one sheet and drop down in sriramus Excel Discussion (Misc queries) 5 October 27th 05 06:55 PM
How can I get a larger list height for a combobox while drop down ? Oscar Excel Programming 4 February 10th 05 02:25 PM
Select a value from a combobox drop down list through code TerryK Excel Programming 2 December 7th 03 07:01 AM


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

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

About Us

"It's about Microsoft Excel"