For every Nth Row

J

Junior728

Hi,
How can i shorten the scripts below so that once it reach every 26th row, it
will perform certain tasks. Currently, i am manual adding the row no for next
26th row. Pls help.

Sheets("Format").Select 'Format got header, start frm Row 2.
Range("A1").Select
NumOfRows = Cells(Rows.Count, 1).End(xlUp).Row
For CurrentRow = 2 To NumOfRows

If CurrentRow = 2 Then
Rows(CurrentRow).Select
Selection.Insert Shift:=xlDown
Cells(CurrentRow, "C").Select
ActiveCell.FormulaR1C1 = "CIS053"
Cells(CurrentRow, "A").Select
ActiveCell.FormulaR1C1 = "H"
End If
If CurrentRow = 29 Then
Rows(CurrentRow).Select
Selection.Insert Shift:=xlDown
Cells(CurrentRow, "C").Select
ActiveCell.FormulaR1C1 = "CIS053"
Cells(CurrentRow, "A").Select
ActiveCell.FormulaR1C1 = "H"
End If
If CurrentRow = 56 Then
Rows(CurrentRow).Select
Selection.Insert Shift:=xlDown
Cells(CurrentRow, "C").Select
ActiveCell.FormulaR1C1 = "CIS053"
Cells(CurrentRow, "A").Select
ActiveCell.FormulaR1C1 = "H"
End If
If CurrentRow = 83 Then
Rows(CurrentRow).Select
Selection.Insert Shift:=xlDown
Cells(CurrentRow, "C").Select
ActiveCell.FormulaR1C1 = "CIS053"
Cells(CurrentRow, "A").Select
ActiveCell.FormulaR1C1 = "H"
End If
If CurrentRow = 110 Then
Rows(CurrentRow).Select
Selection.Insert Shift:=xlDown
Cells(CurrentRow, "C").Select
ActiveCell.FormulaR1C1 = "CIS053"
Cells(CurrentRow, "A").Select
ActiveCell.FormulaR1C1 = "H"
End If
If CurrentRow = 137 Then
Rows(CurrentRow).Select
Selection.Insert Shift:=xlDown
Cells(CurrentRow, "C").Select
ActiveCell.FormulaR1C1 = "CIS053"
Cells(CurrentRow, "A").Select
ActiveCell.FormulaR1C1 = "H"
End If
If CurrentRow = 164 Then
Rows(CurrentRow).Select
Selection.Insert Shift:=xlDown
Cells(CurrentRow, "C").Select
ActiveCell.FormulaR1C1 = "CIS053"
Cells(CurrentRow, "A").Select
ActiveCell.FormulaR1C1 = "H"
End If
Next
 
R

Roger Govier

Hi

Try

Sheets("Format").Select 'Format got header, start frm Row 2.

NumOfRows = Cells(Rows.Count, 1).End(xlUp).Row
For CurrentRow = 2 To NumOfRows Step 27

Cells(CurrentRow, 1).EntireRow.Insert
Cells(CurrentRow, "C") = "CIS053"

Cells(CurrentRow, "A") = "H"
Next
 
D

Don Guillett

Test this on a blank sheet with 1,2, etc copied down. If OK change -3 to
whatever desired.
It works from the BOTTOM UP
Sub insertrows()
For i = Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -3
Rows(i).Insert
Cells(i, "C") = "CIS053"
Cells(i, "A") = "H"
Next i
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top