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
[TABLE="class: head"]
<tbody>[TR="bgcolor: #888888"]
[TH][/TH]
[TH]
A
[/TH]
[TH]
B
[/TH]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
1
[/TD]
[TD]Category[/TD]
[TD]
1​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
2
[/TD]
[TD]Category[/TD]
[TD]
2​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
3
[/TD]
[TD]Category[/TD]
[TD]
3​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
4
[/TD]
[TD]Category[/TD]
[TD]
4​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
5
[/TD]
[TD]Category[/TD]
[TD]
5​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
6
[/TD]
[TD]Category[/TD]
[TD]
6​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
7
[/TD]
[TD]Category[/TD]
[TD]
7​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
8
[/TD]
[TD]Category[/TD]
[TD]
8​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
9
[/TD]
[TD]Category[/TD]
[TD]
9​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
10
[/TD]
[TD]Category[/TD]
[TD]
10​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
11
[/TD]
[TD]Category[/TD]
[TD]
11​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
12
[/TD]
[TD]Category[/TD]
[TD]
12​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
13
[/TD]
[TD]Category[/TD]
[TD]
1​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
14
[/TD]
[TD]Category[/TD]
[TD]
2​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
15
[/TD]
[TD]Category[/TD]
[TD]
3​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
16
[/TD]
[TD]Category[/TD]
[TD]
4​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
17
[/TD]
[TD]Category[/TD]
[TD]
5​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
18
[/TD]
[TD]Category[/TD]
[TD]
6​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
19
[/TD]
[TD]Category[/TD]
[TD]
7​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
20
[/TD]
[TD]Category[/TD]
[TD]
8​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
21
[/TD]
[TD]Category[/TD]
[TD]
9​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
22
[/TD]
[TD]Category[/TD]
[TD]
10​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
23
[/TD]
[TD]Category[/TD]
[TD]
11​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
24
[/TD]
[TD]Category[/TD]
[TD]
12​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
25
[/TD]
[TD]Class[/TD]
[TD]
1​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
26
[/TD]
[TD]Class[/TD]
[TD]
2​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
27
[/TD]
[TD]Class[/TD]
[TD]
3​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
28
[/TD]
[TD]Class[/TD]
[TD]
4​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
29
[/TD]
[TD]Class[/TD]
[TD]
5​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
30
[/TD]
[TD]Class[/TD]
[TD]
6​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
31
[/TD]
[TD]Class[/TD]
[TD]
7​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
32
[/TD]
[TD]Class[/TD]
[TD]
8​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
33
[/TD]
[TD]Class[/TD]
[TD]
9​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
34
[/TD]
[TD]Class[/TD]
[TD]
10​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
35
[/TD]
[TD]Class[/TD]
[TD]
11​
[/TD]
[/TR]
[TR="bgcolor: #FFFFFF"]
[TD="bgcolor: #888888"]
36
[/TD]
[TD]Class[/TD]
[TD]
12​
[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="class: grid"]
<tbody>[TR]
[TD]Sheet: Sheet1[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
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,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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