PC Review


Reply
Thread Tools Rate Thread

Adding values to a combo box

 
 
jbear@wilmingtontrust.com
Guest
Posts: n/a
 
      1st Dec 2006
Good morning, everyone! I'm still learning the in's and out's of Excel
while I work on various projects. Right now, I'm trying to implement a
combo box onto a spreadsheet which will populate based on values
entered on another worksheet within the workbook. There a few factors
complicating my attempts though:

First, the combo box is on Sheet1 and the array is on Sheet2. I've
only had success in my efforts when I put the coding to populate the
combo box with the array information on the "ThisWorkbook" object in
VBA. Here is the code that works under this condition:

Sub Main()

Dim i As Integer
Dim NumCUSIPs As Integer
Dim CUSIPList() As String

' Calls the CUSIPManager function to populate
' the combo box
Call CUSIPManager(NumCUSIPs, CUSIPList())
For i = 1 To NumCUSIPs
Sheets("Sheet1").ComboBox1.AddItem CUSIPList(i)
Next i
Sheets("Sheet1").Select

End Sub

Sub CUSIPManager(CUSIPCount As Integer, CUSIPs() As String)

' Counts the number of CUSIPs related
' to the account and stores them to an array

Sheets("Sheet2").Select
Range("A2").Select
Do While ActiveCell.Value <> ""
CUSIPCount = CUSIPCount + 1
ReDim Preserve CUSIPs(CUSIPCount)
CUSIPs(CUSIPCount) = ActiveCell.Value
ActiveCell.Offset(1).Select
Loop

End Sub

My second problem is that the array of information that will be used to
populate the combo box is of variable size. People could add or remove
information from the array at anytime. Right now, with the coding on
the "ThisWorkbook" object, it works fine. If my code is fine where it
is, then that eliminates problems 1 and 2 and brings me to problem 3...

Problem 3 is that when I first open the workbook, only the first value
in the array is populated. Is there anyway to have the values in the
combo box updated upon opening the worksheet?

I appreciate any insight that anyone can provide. I've been reading
these forums for a few months now for pointers as I've been learning
VBA, but this is the first time that I can officially say "I'm
stumped!". Thanks!

 
Reply With Quote
 
 
 
 
dd
Guest
Posts: n/a
 
      1st Dec 2006
Try this example from Debra Dalgleish at Contextures.

http://www.contextures.com/ComboBoxAddress.zip

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
Good morning, everyone! I'm still learning the in's and out's of Excel
while I work on various projects. Right now, I'm trying to implement a
combo box onto a spreadsheet which will populate based on values
entered on another worksheet within the workbook. There a few factors
complicating my attempts though:

First, the combo box is on Sheet1 and the array is on Sheet2. I've
only had success in my efforts when I put the coding to populate the
combo box with the array information on the "ThisWorkbook" object in
VBA. Here is the code that works under this condition:

Sub Main()

Dim i As Integer
Dim NumCUSIPs As Integer
Dim CUSIPList() As String

' Calls the CUSIPManager function to populate
' the combo box
Call CUSIPManager(NumCUSIPs, CUSIPList())
For i = 1 To NumCUSIPs
Sheets("Sheet1").ComboBox1.AddItem CUSIPList(i)
Next i
Sheets("Sheet1").Select

End Sub

Sub CUSIPManager(CUSIPCount As Integer, CUSIPs() As String)

' Counts the number of CUSIPs related
' to the account and stores them to an array

Sheets("Sheet2").Select
Range("A2").Select
Do While ActiveCell.Value <> ""
CUSIPCount = CUSIPCount + 1
ReDim Preserve CUSIPs(CUSIPCount)
CUSIPs(CUSIPCount) = ActiveCell.Value
ActiveCell.Offset(1).Select
Loop

End Sub

My second problem is that the array of information that will be used to
populate the combo box is of variable size. People could add or remove
information from the array at anytime. Right now, with the coding on
the "ThisWorkbook" object, it works fine. If my code is fine where it
is, then that eliminates problems 1 and 2 and brings me to problem 3...

Problem 3 is that when I first open the workbook, only the first value
in the array is populated. Is there anyway to have the values in the
combo box updated upon opening the worksheet?

I appreciate any insight that anyone can provide. I've been reading
these forums for a few months now for pointers as I've been learning
VBA, but this is the first time that I can officially say "I'm
stumped!". Thanks!


 
Reply With Quote
 
JB
Guest
Posts: n/a
 
      1st Dec 2006
Thank you all for the responses! They helped me with what I was doing.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding New Values to a combo box on the fly =?Utf-8?B?TGVsZQ==?= Microsoft Access 14 16th Sep 2006 10:28 PM
Adding values in combo box on form =?Utf-8?B?RGVubmlzIF9N?= Microsoft Access Forms 5 6th Mar 2006 03:41 PM
Adding values in a combo box when value entered is not the key value =?Utf-8?B?V2VuZHk=?= Microsoft Access Forms 2 26th Oct 2003 10:58 PM
Adding values to Combo box values Mercy Microsoft Access Forms 4 18th Sep 2003 04:50 AM
adding values to combo box mark Microsoft Outlook Form Programming 2 22nd Jul 2003 04:38 PM


Features
 

Advertising
 

Newsgroups
 


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