Sequence function in old verion of excel

nmounir

Board Regular
Joined
Oct 16, 2020
Messages
107
Office Version
  1. 365
Platform
  1. Windows
I am trying to write a formula where I can get numbers from 1 to 20 in 5 columns and 4 rows
So it should be like this
1,2,3,4,5;6,7,8,9,10;11,12,13,14,15;16,17,18,19,20
I have put the semi column above to show when the numbers goes from 5th column to the next row.
This can easily be done with the sequence function but not sure how it can be done with excel 2016. On cell A1 I tried index(row(1:20) ,row(indirect("1:4")&column(A1:E1) but it doesn't work. Any idea ?
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
You could use:

Excel Formula:
((ROW(INDIRECT("A1:E4"))-1)*5+COLUMN(INDIRECT("A1:E4")))
 
Upvote 0
Solution
Put this in your starting cell and copy it across and down...
Excel Formula:
=ROW(A1)*5+COLUMN(A1)-5
 
Upvote 0
For what it's worth, here's a UDF that emulates the SEQUENCE function:

VBA Code:
Public Function Sequence1(Optional r = 1, Optional c = 1, Optional s = 1, Optional step = 1)
Dim op(), r1 As Long, c1 As Long

    ReDim op(1 To r, 1 To c)
    For r1 = 1 To r
        For c1 = 1 To c
            op(r1, c1) = s
            s = s + step
        Next c1
    Next r1
    Sequence1 = op
   
End Function

Dynamic functions.xlsm
ABCDEF
112345
2678910
31112131415
41617181920
5
Sheet5
Cell Formulas
RangeFormula
A1:E4A1=sequence1(4,5)
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
For what it's worth, here's a UDF that emulates the SEQUENCE function:

VBA Code:
Public Function Sequence1(Optional r = 1, Optional c = 1, Optional s = 1, Optional step = 1)
Dim op(), r1 As Long, c1 As Long

    ReDim op(1 To r, 1 To c)
    For r1 = 1 To r
        For c1 = 1 To c
            op(r1, c1) = s
            s = s + step
        Next c1
    Next r1
    Sequence1 = op
  
End Function

Dynamic functions.xlsm
ABCDEF
112345
2678910
31112131415
41617181920
5
Sheet5
Cell Formulas
RangeFormula
A1:E4A1=sequence1(4,5)
Press CTRL+SHIFT+ENTER to enter array formulas.
This is brilliant thank you very much Eric
For what it's worth, here's a UDF that emulates the SEQUENCE function:

VBA Code:
Public Function Sequence1(Optional r = 1, Optional c = 1, Optional s = 1, Optional step = 1)
Dim op(), r1 As Long, c1 As Long

    ReDim op(1 To r, 1 To c)
    For r1 = 1 To r
        For c1 = 1 To c
            op(r1, c1) = s
            s = s + step
        Next c1
    Next r1
    Sequence1 = op
  
End Function

Dynamic functions.xlsm
ABCDEF
112345
2678910
31112131415
41617181920
5
Sheet5
Cell Formulas
RangeFormula
A1:E4A1=sequence1(4,5)
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
For what it's worth, here's a UDF that emulates the SEQUENCE function:
Since, for your function, you have to select the range you want to fill in before using CTRL+SHIFT+ENTER to commit the array formula, there does not appear to be a need to have the user specify how many rows and columns to calculate as the function can do that on its own. Here is a function (I called it Sequencer) based on your function that only takes two arguments both of which are optional... the start number for the sequence and the step to apply to each value.
VBA Code:
Function Sequencer(Optional ByVal Start As Long = 1, _
                   Optional ByVal Step As Long = 1)
  Dim R As Long, C As Long, Arr As Variant
  With Application.Caller
    ReDim Arr(1 To .Rows.Count, 1 To .Columns.Count)
    For R = 1 To .Rows.Count
      For C = 1 To .Columns.Count
        Arr(R, C) = Start
        Start = Start + Step
      Next
    Next
  End With
  Sequencer = Arr
End Function
 
Upvote 0
Here is a function (I called it Sequencer) based on your function that only takes two arguments both of which are optional... the start number for the sequence and the step to apply to each value.
Clever, Rick. I hadn't thought of that. I wrote UDF's for all the new Dynamic Array functions before I had access to them for real. So I tried to make them conform as closely as possible to the published descriptions. But of course there's no need to stick to that if it's not necessary.
 
Upvote 0

Forum statistics

Threads
1,214,801
Messages
6,121,644
Members
449,045
Latest member
Marcus05

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