+ Reply to Thread
Results 1 to 7 of 7

Insert cells after row value changes

  1. #1
    Registered User
    Join Date
    02-05-2013
    Location
    Canberra, Australia
    MS-Off Ver
    Excel 2010
    Posts
    39

    Insert cells after row value changes

    I'm after code to add two rows of cells but only 6 columns wide every time a value changes in a columns. e.g.
    before;
    1
    1
    1
    2
    2
    3
    3
    3
    3

    after;
    1
    1
    1
    (insert two rows, 6 columns wide here)
    2
    2
    (insert two rows, 6 columns wide here)
    3
    3
    3
    3
    (insert two rows, 6 columns wide here)

    This is the code i have so far;

    Sub InsertBlankRows()

    Dim LastRow As Long
    Dim i As Long

    LastRow = Cells(Rows.Count, "A").End(xlUp).Row

    For i = LastRow To 2 Step -1
    If i = 2 Then
    'Do nothing
    ElseIf Cells(i, "A") <> Cells(i - 1, "A") Then
    Cells(i, "A").Insert
    End If
    Next i

    End Sub

    This code inserts one cell below each of the values when they change but one column only

    help would be greatly appreciated.

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Insert cells after row value changes

    May be this...

    Please Login or Register  to view this content.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    02-05-2013
    Location
    Canberra, Australia
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Insert cells after row value changes

    That works for the insertion of two rows, but I only need two new rows in columns A:F as I have other data in the next columns. Any ideas?

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Insert cells after row value changes

    Try this...

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-05-2013
    Location
    Canberra, Australia
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Insert cells after row value changes

    Works Beautifully! My data doesn't start until row three, Is there a way I can get it to stop at row three so It doesn't insert cells below the column header row. I have a title in row one and then column headers in row two.

  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Insert cells after row value changes

    Glad it helps you and thanks for the feedback

    Just change the start row here...

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-05-2013
    Location
    Canberra, Australia
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Insert cells after row value changes

    Thankyou heaps SixthSence, this now works a treat!!

+ 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