Consulting

Results 1 to 5 of 5

Thread: Insert row after data change

  1. #1
    VBAX Regular
    Joined
    Mar 2008
    Posts
    13
    Location

    Insert row after data change

    I need to search through column "A" and when ever the data changes I need to insert a row. For instance I would need a row between 100002447724 and 100002447725.
    I am learning the basics of VBA and would like a simple code to do this if anyone can help please.
    Last edited by hwfan123; 12-03-2009 at 08:05 AM.

  2. #2
    VBAX Regular
    Joined
    Mar 2008
    Posts
    13
    Location

    oops

    the numbers listed should be in a column here is an attachment if that helps

  3. #3
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Greetings hwfan123,

    Quote Originally Posted by hwfan123
    I need to search through column "A" and when ever the data changes I need to insert a row.
    Okay, that part makes sense.

    Quote Originally Posted by hwfan123
    For instance I would need a row between 100002447724 and 100002447725....
    But this part, not so much

    Can you describe what would be the factor(s) in determining where a row should get inserted, and what is the change that we are making that needs to initiate this?

    Mark

    PS - I'm not sure that you can go back and edit your first post after a second, but if the edit button is still available... getting rid of that long string would fix the window.

  4. #4
    VBAX Expert
    Joined
    Feb 2005
    Location
    Nanaimo, British Columbia, Cananda
    Posts
    568
    Location
    hw, try this

    [VBA]
    Option Explicit

    Sub SplitRows()

    Dim i As Long
    Dim LastRow As Long

    'Speed
    Application.ScreenUpdating = False

    'Get end of data
    LastRow = Range("A" & Rows.Count).End(xlUp).Row

    'Do all from bottom up so insert rows does not change counter 'i'
    For i = LastRow To 2 Step -1

    'Compare current tow to one above it
    If Cells(i, 1) <> Cells(i - 1, 1) Then
    'No match = insert a row
    Cells(i, 1).EntireRow.Insert
    End If
    Next i

    'Reset

    Application.ScreenUpdating = True

    End Sub
    [/VBA]
    Cheers,

    dr

    "Questions, help and advice for free, small projects by donation. large projects by quote"

    http:\\www.ExcelVBA.joellerabu.com

  5. #5
    VBAX Regular
    Joined
    Mar 2008
    Posts
    13
    Location
    That worked perfectly thanks so much. That will save a lot of time.

Posting Permissions

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