Repeat 320 rows and then increment in excel 2007

patelvin21

New Member
Joined
Jun 17, 2011
Messages
3
i need a macro or formula for repeating 320 rows with the same value and then incrementing with next number and copy that for other 320 rows and so on,

which is like

ColumnA
1
1
1
2
2
2
...

here just i had shown for just 3rows which i need it for 320 rows to do using a macro or formula. And also i had used number here but it is a character in the field what i am using.

When i recorded using a macro function i got the following function,

Sub Repeat()
'
' Repeat Macro
'
' Keyboard Shortcut: Ctrl+Shift+B
'
Selection.AutoFill Destination:=Range("B18633:B18634"), Type:=xlFillDefault
Range("B18633:B18634").Select
Range("B18634").Select
Selection.AutoFill Destination:=Range("B18634:B18953"), Type:=xlFillCopy
Range("B18634:B18953").Select
ActiveWindow.SmallScroll Down:=300
Range("B18953").Select
End Sub

But with this i am able to do for particular range, i need it to do for 1400 times copying the same value in 320 rows and increment it and then again copy it.

Can any of u please help me.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
You'll need to adjust this code for the range etc but try:
Code:
Sub UnicornsShouldntExit ()
 
Dim i As Long, j As Long, k As Long
 
Application.ScreenUpdating = False
 
j = 1
k = Range("B" & j)

For i = 1 To 1400
    With Range("B" & j)
        .Value = k
        .Copy
        .Resize(320).PasteSpecial Paste:=xlPasteValues
        k = k + 1
    End With
    j = j + 320
Next i

Application.ScreenUpdating = True
 
End Sub
 
Upvote 0
Although I think if you repeat that code 1,400 times, you'll be trying to copy more than the number of rows Excel allows (I may be wrong about this)
 
Upvote 0
if all you wanted were the numbers, then

Code:
Sub test()
    For i = 1 To 1400
        Cells((i - 1) * 320 + 1, 1).Resize(320).Value = i
    Next
End Sub
Would work

If the values are non linear, maybe even text, then the approach may have to be different.

You may need to explain more fully what you are trying to achieve.
 
Upvote 0
Although I think if you repeat that code 1,400 times, you'll be trying to copy more than the number of rows Excel allows (I may be wrong about this)
It's okay Jack, 2007 has over 1,000,000 rows (2^20 to be exact), the OP requires about 450,000 for this task
 
Upvote 0
Thanks you all for the immediate response.. i had tried JacDanIce code but here my value is "MP_CF_8.55_W153". Now this value is in column B and i want to repeat this one for 320 rows and in 321st row it should increment with "MP_CF_8.55_W154" and then copy for remaining 319 rows the same should repeat until my value ends with "MP_CF_8.55_W1400".

thanks for help.
 
Upvote 0
Something like?

Code:
Sub test()
    For i = 1 To 1400
        Cells((i - 1) * 320 + 1, 2).Resize(320).Value = "MP_CF_8.55_W" & i
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,903
Members
452,948
Latest member
Dupuhini

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