Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default insert blank line at change of year

I have a spreadsheet with a column of sorted dates like this

27-Feb-01
27-Feb-01
01-Feb-02
01-Feb-02
01-Feb-02

I would like a macro that can insert a row at each change of year. Does
anyone have any ideas how to do this?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default insert blank line at change of year

Assume first date is in A2; dates in column A.

lastrow = cells(rows.count,1).End(xlup).Row
for i = lastrow to 3 Step -1
if Year(cells(i,1)) < Year(cells(i-1,1)) then
rows(i).Insert
end if
Next

--
Regards,
Tom Ogilvy


"BillyRogers" wrote in message
...
I have a spreadsheet with a column of sorted dates like this

27-Feb-01
27-Feb-01
01-Feb-02
01-Feb-02
01-Feb-02

I would like a macro that can insert a row at each change of year. Does
anyone have any ideas how to do this?



  #3   Report Post  
Posted to microsoft.public.excel.programming
ben ben is offline
external usenet poster
 
Posts: 67
Default insert blank line at change of year

this assumes all dates are in Column 1



Sub EmptyRow()
Dim cou As Integer, MPStr As String, MPString As String
For cou = 1 To ActiveSheet.UsedRange.Rows.Count - 1
MPStr = Format(ActiveSheet.Cells(cou, 1), "YY")
MPString = Format(ActiveSheet.Cells(cou + 1, 1), "YY")
If Not Val(MPString) = Val(MPStr) Then
ActiveSheet.Rows(Trim(Str((cou + 1)))).Insert
cou = cou + 1
End If
Next
End Sub



--
When you lose your mind, you free your life.
Ever Notice how we use '' for comments in our posts even if they aren''t
expected to go into the code?


"BillyRogers" wrote:

I have a spreadsheet with a column of sorted dates like this

27-Feb-01
27-Feb-01
01-Feb-02
01-Feb-02
01-Feb-02

I would like a macro that can insert a row at each change of year. Does
anyone have any ideas how to do this?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default insert blank line at change of year

Thank guys both of those worked great. I would also like to insert in the
blank cell above each change in year "10th Anniversary" if the dates were
ten years ago, "9th anniversary"(in bold) etc.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default insert blank line at change of year

Ben,

I just discovered a flaw in your code. you start out looping using the
rowcount from the top, but everytime you add a space it pushes the last row
further away so your original row count is not high enought to cycle throught
all the rows it needs to.


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
How do I insert a blank line when category changes castleds Excel Discussion (Misc queries) 2 September 27th 06 09:10 PM
insert a blank in every second line of a row EliseT Excel Discussion (Misc queries) 6 June 5th 06 01:43 PM
Insert blank line macro laidebug Excel Worksheet Functions 1 April 14th 06 11:56 PM
Insert Blank Line Sherry Excel Discussion (Misc queries) 8 January 31st 06 03:37 PM
auto insert blank line Little pete Excel Discussion (Misc queries) 4 August 29th 05 09:48 PM


All times are GMT +1. The time now is 10:15 PM.

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

About Us

"It's about Microsoft Excel"