Extract a subset of an array?

343GS

New Member
Joined
Jun 29, 2017
Messages
14
Hello everybody!
I am pretty new to vba but I am trying to learn step by step.
My question is: is there a way to extract n elements of a one-dimensional array?

For example, I created this array (mazzo):

Function GeneraMazzoCarte() As Long()
Dim mazzo(1 To 40) As Long, i As Long

For i = 1 To 40
mazzo(i) = i
Next
GeneraMazzoCarte = mazzo

End Function


Is there a way to extract, for example, the first 7 elements of it?

Thank you all for help!
 
Code:
  Dim subset(1 To 7) As Long
  For i = 1 To 7
    subset(i) = mazzo(i)
  Next i
 
Upvote 0

Forum statistics

Threads
1,226,812
Messages
6,193,116
Members
453,777
Latest member
Miceal Powell

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