Formula needed to repeat pattern

ymurray

New Member
Joined
Apr 1, 2019
Messages
4
I have to populate various spreadsheets using the following number sequence:


1,1,1,1,1,1
2,2,2,2,2,2,2,2,2,2,2,2,2
3,3,3,3,3,3
4,4,4,4,4,4,4,4,4,4,4,4,4
etc..




So basically, I have to follow sequential numbers in the special pattern of 6 instances of 1, 13 instances of 2, 6 instances of 3, 13 instances of 4, etc. I have to go all the way down to 80 instances. Is there a formula I can use in order to not have to do this manually? I have about 4 different spreadsheets I need to do this for.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
As it alternates 6 & 13 for numbers 1 to 80 in B1 put 6, B2 put 13 then copy these 2 cells all the way down to B80 (so that B1:B80) consists of 6,13,6,13...
Then in column C enter =1 In C1 and for C2 put =1+C1 -> drag this down to C80
Now in column A put in: (For cell A1)
=LEFT(REPT(C1&",",B1),LEN(REPT(C1&",",B1))-1)
Drag that down to A80
 
Upvote 0
Hi & welcome to MrExcel.
How about in A1
=REPT(ROW()&",",5)&ROW()
In A2
=REPT(ROW()&",",12)&ROW()
Then grab both cells & fill down
 
Upvote 0
I'm sorry for not explaining this better, but the numbers will actually be going down a column, not a row. So it will look like this:


1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
3
3
3
3
3
3
4
4
4
4
4
4
4
4
4
4
4
4
4
 
Upvote 0
Okay so this should work for what you are looking for:

Firstly this macro assumes you have setup the data horizontally, to do this follow these steps:

1) Open a blank worksheet
2) Highlight A1:F1 and enter =ROW() followed by CTRL+Enter (1 should appear in cells A1:F1)
3) Highlight A2:M2 and enter = ROW() followed by CTRL+Enter (2 should appear in cells A2:M2)
4) Copy cells A1:M2 and highlight cells A3:A80 and paste
5) Copy A1:M80 and paste as values
6) With A1:M80 copied right click in cell N1 and Paste as transpose
7) Delete columns A:M so that you now have 80 columns of data (A:CB) which show 1 up to 80 as the columns progress
8) Run the macro below:

Code:
Sub CopyNums()
    Application.ScreenUpdating = False
    Dim j As Integer
        For j = 2 To 80
            Range(Cells(1, j), Cells(13, j)).Select
            Selection.Cut
            Cells(Cells(Rows.Count, 1).End(xlUp).Row + 1, 1).Select
            ActiveSheet.Paste
        Next j
    Application.ScreenUpdating = True
End Sub

Column A should now have 760 rows as desired (6+13)*40 (alternating patterns 6 + 13 multiplied 40 times as this is how many repetitions of the pattern there is)
 
Upvote 0
Another option
Code:
Sub ymurray()
   Dim i As Long, j As Long
   
   j = 1
   For i = 1 To 80 Step 2
      Cells(j, 1).Resize(6).Value = i
      Cells(j + 6, 1).Resize(13).Value = i + 1
      j = j + 19
   Next i
End Sub
 
Upvote 0
Okay so this should work for what you are looking for:

Firstly this macro assumes you have setup the data horizontally, to do this follow these steps:

1) Open a blank worksheet
2) Highlight A1:F1 and enter =ROW() followed by CTRL+Enter (1 should appear in cells A1:F1)
3) Highlight A2:M2 and enter = ROW() followed by CTRL+Enter (2 should appear in cells A2:M2)
4) Copy cells A1:M2 and highlight cells A3:A80 and paste
5) Copy A1:M80 and paste as values
6) With A1:M80 copied right click in cell N1 and Paste as transpose
7) Delete columns A:M so that you now have 80 columns of data (A:CB) which show 1 up to 80 as the columns progress
8) Run the macro below:

Code:
Sub CopyNums()
    Application.ScreenUpdating = False
    Dim j As Integer
        For j = 2 To 80
            Range(Cells(1, j), Cells(13, j)).Select
            Selection.Cut
            Cells(Cells(Rows.Count, 1).End(xlUp).Row + 1, 1).Select
            ActiveSheet.Paste
        Next j
    Application.ScreenUpdating = True
End Sub

Column A should now have 760 rows as desired (6+13)*40 (alternating patterns 6 + 13 multiplied 40 times as this is how many repetitions of the pattern there is)


I'm with you up until running the macro. Whenever I run the macro, I receive an error that says:

Compile Error

Only comments may appear after End Sub, End Function, or End Property.
 
Upvote 0
Or a formula:

[Table="width:, class:grid"][tr][td="bgcolor:#C0C0C0"][/td][td="bgcolor:#C0C0C0"]
A​
[/td][td="bgcolor:#C0C0C0"]
B​
[/td][/tr][tr][td="bgcolor:#C0C0C0"]
1​
[/td][td="bgcolor:#F3F3F3"]
[/td][td="bgcolor:#F3F3F3"]
[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
2​
[/td][td]
1​
[/td][td]A2: =4*INT((ROWS($A$2:A2) - 1)/38) + MATCH(MOD(ROWS(A$2:A2) - 1, 38), {0,6,19,25})[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
3​
[/td][td]
1​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
4​
[/td][td]
1​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
5​
[/td][td]
1​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
6​
[/td][td]
1​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
7​
[/td][td]
1​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
8​
[/td][td]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
9​
[/td][td]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
10​
[/td][td]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
11​
[/td][td]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
12​
[/td][td]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
13​
[/td][td]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
14​
[/td][td]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
15​
[/td][td]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
16​
[/td][td]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
17​
[/td][td]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
18​
[/td][td]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
19​
[/td][td]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
20​
[/td][td]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
21​
[/td][td]
3​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
22​
[/td][td]
3​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
23​
[/td][td]
3​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
24​
[/td][td]
3​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
25​
[/td][td]
3​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
26​
[/td][td]
3​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
27​
[/td][td]
4​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
28​
[/td][td]
4​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
29​
[/td][td]
4​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
30​
[/td][td]
4​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
31​
[/td][td]
4​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
32​
[/td][td]
4​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
33​
[/td][td]
4​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
34​
[/td][td]
4​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
35​
[/td][td]
4​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
36​
[/td][td]
4​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
37​
[/td][td]
4​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
38​
[/td][td]
4​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
39​
[/td][td]
4​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
40​
[/td][td]
5​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
41​
[/td][td]
5​
[/td][td][/td][/tr]
[/table]
 
Upvote 0
I'm with you up until running the macro. Whenever I run the macro, I receive an error that says:

Compile Error

Only comments may appear after End Sub, End Function, or End Property.

Strange, it works just fine for me, have you tried pasting the code in to a new module within the workbook?

From github the error states: "
  • You placed executable code outside a procedure. Any nondeclarative lines outside a procedure must begin with a comment delimiter ( ' ). Declarative statements must appear before the first procedure declaration. Comments are ignored when the code executes."
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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