How to create a dynamic array?

hilyete

Active Member
Joined
Aug 19, 2009
Messages
293
I want to create a dynamic array that stores the values of any cells selected in column A and then, when a commandbutton is clicked, list all of the values in one cell (B8), not summed, but just: 34, 17, 19, 22, 42, etc.
How do I create the array with VBA and store the selected values, then print them to cell B8 regardless of how many there are?
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Try this

Code:
Private Sub CommandButton1_Click()
Dim c As Range, s As String
For Each c In Intersect(Selection, Columns("A"))
    s = s & c.Value & ", "
Next c
If s <> "" Then Range("B8").Value = Left(s, Len(s) - 2)
End Sub
 
Upvote 0
Thanks for responding Peter,

Of course your code works splendidly. I was hoping to be able to single out some of the digits by referring to the specific array selection, like "choice(3)". Is that possible to do with the code you have given me?
 
Upvote 0
Sorry, I think that you'll have to provide some more of your existing code. How do we know that Choice(3) is "selected"?
 
Upvote 0
I'm sorry VoG, I realize it isn't very clear. I'm actually hoping to use the array concept in a powerpoint/excel project. The idea is that the person can click a commandbutton when any given slide is visible, and the slide's index number would be stored in an array. At the end of the presentation, all slides except the ones in the array are hidden. I just don't know how to work with dynamic arrays, like how to add the new info to the existing array on a button click), and was hoping my example would provide me with the basic information to put it together.
 
Upvote 0
Thanks Peter,

That's what I needed, just a good clear example. I was able to adapt it to check each slide in a powerpoint to see if a checkbox was "true", save that slides index number in the array, and then at the end of the presentation, hide all the slides that had been checked. Of course, it's 3 am here, lol but I've got it done.

Tom
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,626
Members
452,933
Latest member
patv

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top