macro to insert rows

F

Flipper

Can someone please help me wrtie a macro that will insert 1 blank row between
the end of one month and the start of another? Example: I want a row
between
1/31/200 and 2/1/2000. I have a large spreadsheet I would like to do this
with. Also, if possible, I would also like a formula inserted in that blank
row that calculates the average for the month in column 2.
1/27/2000 5.69
1/28/2000 5.81
1/31/2000 5.84
2/1/2000 5.84
2/2/2000 5.88
 
J

Jacob Skaria

Try the below macro with your data in Col A and Col B starting from
Row1...Hope you dont have any blank rows in between...

Sub MyMacro()
Dim lngRow As Long, lngRRow As Long
lngRow = 2: lngRRow = 1
Do While Range("A" & lngRow) <> ""
If Month(Range("A" & lngRow)) <> Month(Range("A" & lngRow - 1)) Then
Rows(lngRow).Insert
Range("B" & lngRow).Formula = "=SUM(B" & lngRRow & ":B" & lngRow - 1 & ")"
lngRRow = lngRow + 1: lngRow = lngRRow
End If
lngRow = lngRow + 1
Loop
Range("B" & lngRow).Formula = "=SUM(B" & lngRRow & ":B" & lngRow - 1 & ")"
End Sub

If this post helps click Yes
 

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

Insert rows macro. 2
Insert a Row and then Sum 1
Macro for averaging 3
Insert Multiple Blank Rows 3
Insert letter in cell 2
insert row when sum of values equals 100 3
Insert a row 3
Script to insert Row 2

Top