How to create an array with x numbers that increments from 1 to x, then use it in formula [VBA]?

gravanoc

Active Member
Joined
Oct 20, 2015
Messages
348
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
My current need is for a flexible array as mentioned in the title, so I can insert it into a formula with VBA.

This is how it always starts:
Excel Formula:
=SMALL(myRange, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10})

Next I would like for it to be the same except dropping the 10.
Excel Formula:
=SMALL(myRange, {1, 2, 3, 4, 5, 6, 7, 8, 9})

This continues until the iteration is using 1 by itself.

My current solution would be to use Select Case to determine which to go with; however, the other problem is that array variables aren't working when I insert them via otherRange.Formula2 = "...".
Specifically, I've tried setting a variable named Arr = Array(1, 2, 3,4...., 10), then putting it in:

VBA Code:
otherRange.Formula2 = "=SMALL(" & myRange.Address & ", {" & Arr & "})"

Other variations are also not working.

Thanks.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Since you have Excel 365, try:

VBA Code:
otherRange.Formula2 = "=SMALL(" & myRange.Address & ", SEQUENCE(," & n & "))"

where n is the upper bound.
 
Upvote 0
Solution
Not entirely sure what your asking for, but maybe
VBA Code:
OtherRange.Formula2 = "=SMALL(" & myrange.Address & ", sequence(" & myrange.Rows.Count & "))"
 
Upvote 0

Forum statistics

Threads
1,215,039
Messages
6,122,802
Members
449,095
Latest member
m_smith_solihull

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