+ Reply to Thread
Results 1 to 2 of 2

Auto insert row based on data

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-04-2006
    Posts
    201

    Auto insert row based on data

    Hi,

    is there away using VBA to do the following?

    I have a list of data in column 'A' which may repeat the same text and will then be differnet. I want to insert a row before the text changes.....here is an example

    so...column 'A' may look like this

    Loop
    Loop
    Loop
    Pool
    Pool
    Rate
    Rate
    Rate

    I want to insert a row under each change....so it will look like this

    Loop
    Loop
    Loop

    Pool
    Pool
    Rate

    Rate
    Rate

    any ideas???

    thanks in advance

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Maybe


    Sub InsertRow()
    Dim LastRow As Long, i As Long
    LastRow = Cells(Rows.Count, "A").End(xlUp).Row
    
        For i = LastRow To 2 Step -1
            If Cells(i, "A").Value <> Cells(i - 1, "A").Value Then
                Rows(i).EntireRow.Insert shift:=xlDown
            End If
        Next i
    End Sub
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

+ 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