#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 51
Default macro to insert rows

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



--
Allan
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default macro to insert rows

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
---------------
Jacob Skaria


"Flipper" wrote:

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



--
Allan

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
A Macro to Insert Rows Confused_in_Houston[_2_] Excel Discussion (Misc queries) 1 February 2nd 09 05:26 PM
Insert rows with condition using macro Shazza Excel Discussion (Misc queries) 6 September 5th 08 12:06 AM
Insert rows macro. Johnny Excel Discussion (Misc queries) 2 November 13th 07 08:38 PM
Insert Rows Macro A.S. Excel Discussion (Misc queries) 7 October 31st 07 02:03 PM
asking again, macro to insert rows Luke Excel Worksheet Functions 12 September 18th 05 06:32 PM


All times are GMT +1. The time now is 12:37 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"