Interval row count

bsquad

Board Regular
Joined
Mar 15, 2016
Messages
194
I am not sure why I am having so much trouble figuring out the VBA code on this one; I am just trying to paste values 1 to 12 in Column B for each cell occupied in Column A. I know its most probably super simple



Excel 2013 32 bit
A
B
1
Category
1​
2
Category
2​
3
Category
3​
4
Category
4​
5
Category
5​
6
Category
6​
7
Category
7​
8
Category
8​
9
Category
9​
10
Category
10​
11
Category
11​
12
Category
12​
13
Category
1​
14
Category
2​
15
Category
3​
16
Category
4​
17
Category
5​
18
Category
6​
19
Category
7​
20
Category
8​
21
Category
9​
22
Category
10​
23
Category
11​
24
Category
12​
25
Class
1​
26
Class
2​
27
Class
3​
28
Class
4​
29
Class
5​
30
Class
6​
31
Class
7​
32
Class
8​
33
Class
9​
34
Class
10​
35
Class
11​
36
Class
12​

<tbody>
</tbody>
Sheet: Sheet1

<tbody>
</tbody>
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
One way

Code:
Sub aTest()
    Dim i As Long
    
    With Sheets("Sheet1")
        For i = 1 To .Cells(.Rows.Count, "A").End(xlUp).Row
            .Cells(i, 2) = ((i - 1) Mod 12) + 1
        Next i
    End With
End Sub

Hope this helps

M.
 
Upvote 0
Another way without a loop:

Code:
Sub test()
With Range("B1:B" & Range("A" & Rows.Count).End(xlUp).Row)
    .Formula = "=MOD(ROWS($A$1:A1)-1,12)+1"
    .Value = .Value
End With
End Sub
 
Upvote 0
Just out of curiosity, what is the purpose of this?

=MOD(ROWS($A$1:A1)-1,12)+1

Providing you start in row 1 so the count is right...

Edit: Ah nvm, I see. I did not go all the way to row 12. :)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,331
Members
449,077
Latest member
jmsotelo

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