Solved

Set the value selected for an ActiveX ComboBox using VBA

Posted on 2013-05-22
5
5,153 Views
Last Modified: 2013-05-30
I am trying to set the value selected for an ActiveX Control Box using VBA to the first item in the list or blank. When recording the macro no code is produced for the action.
0
Comment
Question by:tjd71
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 35

Accepted Solution

by:
[ fanpages ] earned 500 total points
ID: 39190128
Hi,

Set the ListIndex property of the ComboBox to 0 (zero).

For example:
Option Explicit
Public Sub Create_ComboBox1()

  ActiveSheet.OLEObjects.Add(ClassType:="Forms.ComboBox.1", _
                             Link:=False, _
                             DisplayAsIcon:=False, _
                             Left:=50, _
                             Top:=50, _
                             Width:=100, _
                             Height:=18).Select

  ActiveSheet.OLEObjects("ComboBox1").Object.AddItem "First"
  ActiveSheet.OLEObjects("ComboBox1").Object.AddItem "Second"
  ActiveSheet.OLEObjects("ComboBox1").Object.AddItem "Third"
  ActiveSheet.OLEObjects("ComboBox1").Object.AddItem "Fourth"
  ActiveSheet.OLEObjects("ComboBox1").Object.AddItem "Fifth"
  
  ActiveSheet.OLEObjects("ComboBox1").Object.ListIndex = 0&     ' Select the first item
  
End Sub

Open in new window


BFN,

fp.
0
 

Author Comment

by:tjd71
ID: 39198295
Thanks FP, I am away from the office until Thursday and will try it then.
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 39198635
OK.  Thanks for letting me know.
0
 

Author Closing Comment

by:tjd71
ID: 39206572
Hi Fp,

Thanks :) Too easy once you know how.

Cheers
tjd71
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 39206908
:) You're welcome.

Sometimes it is the simplest of things that become the most difficult to discover!

Good luck with the rest of your project.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question