+ Reply to Thread
Results 1 to 5 of 5

insert blank line at change of year

  1. #1
    BillyRogers
    Guest

    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. #2
    Tom Ogilvy
    Guest

    Re: 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" <BillyRogers@discussions.microsoft.com> wrote in message
    news:A11A7FF6-81A7-4D8B-8713-6B48ECD5B2CA@microsoft.com...
    > 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. #3
    ben
    Guest

    RE: 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. #4
    BillyRogers
    Guest

    RE: 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. #5
    BillyRogers
    Guest

    RE: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1