PDA

View Full Version : repeating one number



CORAL
12-17-2014, 01:00 PM
hi i want that in one column we have 24 of 1 then 24 of 2 then 24 of 3 up to 31 could you please send me the code

Admin
12-17-2014, 04:47 PM
In C1: 24
In C2: 31

In C3 and copied down

=if(rows(c$3:c3)<=$c$2,$c$1&" of "&rows(c$3:c3),"")

is it what you are looking for ?

azlinzi
12-17-2014, 07:57 PM
Or, you can put the following line in C3 and copy down:
=IF(ROWS(C$3:C3)<$C$1*$C$2,INT(ROWS(C$3:C3)/24+1),"")

Rick Rothstein
12-18-2014, 09:11 PM
Or, in code, as requested...

Sub InsertThirtyOneSetsOfTwentyFourEach()
Dim X As Long, Z As Long, Index As Long, Nums(1 To 744, 1 To 1)
Const StartCell As String = "A1"
For X = 1 To 31
For Z = 1 To 24
Index = Index + 1
Nums(Index, 1) = X
Next
Next
Range(StartCell).Resize(744) = Nums
End Sub


Note: Adjust the starting cell address (as shown in red above) to match your actual requirements.

snb
12-19-2014, 04:02 PM
or


Sub M_snb()
[A1].Resize(24 * 31).Name = "snb_002"
[Snb_002] = [index(int((row(snb_002)-1)/24)+1,)]
End Sub

azumi
12-20-2014, 04:28 PM
Assumed your data on A1 and down, put this on B1 and copied down:

=A1&" Of "&COUNTIF($A$1:A1,A1)

Scott Huish
01-06-2015, 02:57 AM
Sub Insert24x31()
With Range("A1:A744")
.Formula = "=INT((ROW()-1)/24)+1"
.Value = .Value
End With
End Sub