VBA to insert blank row every 26th row and add text

fvisions

Board Regular
Joined
Jul 29, 2008
Messages
191
Office Version
  1. 365
Platform
  1. Windows
Hello, I have a data set that can be 1500 to 2000 rows at any given month. I am looking for a vba to start at the bottom of the data and count up to insert a blank row between hour 2 & 3 (the first count is 22 then it is 26 thereafter to the top.) then change each inserted blank row to be "*2"

The spreadsheet looks like this; (starting at cell A1)

Original >>Revised

Meter Meter
Daily Daily
*** ***
6 6
1 1
2 2
3 *2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
20 19
21 20
22 21
23 22
24 23
*** 24
6 ***
1 6
2 1
3 2
4 *2
5 3
6 4
7 5
8 6
9 7
10 8
11 9
12 10
13 11
14 12
15 13
16 14
17 15
18 16
19 17
20 18
21 19
22 20
23 21
24 22
*** 23
24
*** and so on to the end.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hey fvisions,

Try the below code & let me know if that's what you need

Code:
Sub Insert_Rows()
Dim lRow As Long
lRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row - 22 'Assuming your data is in column "A", change accordingly
For x = lRow To 2 Step -26
    With Rows(x)
        .Insert
        .Columns(1).Offset(-1, 0).Value = "*2"
    End With
Next x
End Sub

 
Upvote 0

Forum statistics

Threads
1,216,117
Messages
6,128,935
Members
449,480
Latest member
yesitisasport

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