How to Increment a Number in Excel With Pattern

jdphilippe

New Member
Joined
Aug 30, 2017
Messages
18
So I have a question (which I hope someone can give a quick answer). What I am trying to achieve is as follows:

1
2
2
3
3
3
4
4
4
4

So essentially have the number pattern/repeat based on the number itself and also increase. I need this to go all the way to at least number 36. Anyone has a quick solution? Many thanks.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Here is a macro that should do what you want (set the maximum number to count to in the MaxNumber variable and change the red A's to the column letter designation where you want the output to go to)...
Code:
[table="width: 500"]
[tr]
	[td]Sub PatternedNumberSequence()
  Dim MaxNumber As Long, CellCount As Long
  [B][COLOR="#0000FF"]MaxNumber = 36[/COLOR][/B]
  CellCount = MaxNumber * (MaxNumber + 1) / 2
  Range("[B][COLOR="#FF0000"]A[/COLOR][/B]1:[B][COLOR="#FF0000"]A[/COLOR][/B]" & CellCount) = Application.Transpose(Split(Join(Application.Transpose(Evaluate("IF({1},REPT(ROW(1:" & MaxNumber & ")&"" "",Row(1:" & MaxNumber & ")))")), "")))
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
Simply amazing! I knew it could be a simple macro to give me my solution but I am just not an expert like all the great minds on here. Thank you again, tried it and it worked.
 
Upvote 0
Simply amazing! I knew it could be a simple macro to give me my solution but I am just not an expert like all the great minds on here. Thank you again, tried it and it worked.
The macro does not have a lot of lines of code, but I am not sure too many would call it "simple" (there is a lot going on in that last line of code). In any event, I am glad it worked for you the way you wanted.
 
Upvote 0
The macro does not have a lot of lines of code, but I am not sure too many would call it "simple" (there is a lot going on in that last line of code). In any event, I am glad it worked for you the way you wanted.
Here is another macro that will also work... it is a little simpler in construction and should be easier to dissect (unlike my first macro, this one uses a loop).
Code:
[table="width: 500"]
[tr]
	[td]Sub PatternedNumberSequence()
  Dim X As Long, MaxNumber As Long
  MaxNumber = 36
  For X = 1 To MaxNumber
    Cells(Rows.Count, "A").End(xlUp).Offset(-(X > 1)).Resize(X) = Application.Transpose(Split(Application.Rept(X & " ", X)))
  Next
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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