Insert Row based on above cell value
Results 1 to 2 of 2

Thread: Insert Row based on above cell value
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Jun 2019
    Posts
    1
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Insert Row based on above cell value

    I want to be able to select the column that I want it to compare the value and if the value changes then insert a row. This code works but it doesn't allow me select the column I want to use and it doesn't stop at the last row that has data it continues to the end of he spreadsheet.

    Sub Insert()
    Dim LR Ad Long
    Application.ScreenUpdating = False
    LR = Range("B" & Rows.Count).End9xlUp).Row
    Range("B" &LR).Select
    Do Until ActiveCell.Row=2
    If ActiveCel.Value<> Active.Offset(-1).Value Then
    ActieCell.Resze(1).EntireRow.Insert
    End If
    ActiveCell.Ofse(-1).Select
    Loop
    Application.ScreenUpdateing - False
    End Sub

  2. #2
    Board Regular MARK858's Avatar
    Join Date
    Nov 2010
    Location
    Southern England
    Posts
    10,957
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    2 Thread(s)

    Default Re: Insert Row based on above cell value

    This code works
    I doubt it with the typo's. Did you copy/paste the code in the thread or retype it?

    Anyway try (untested)...

    Code:
    Sub InsertBlankRows()
    
        Dim LastRow As Long
        Dim i As Long
        Application.ScreenUpdating = False
    
        LastRow = Columns(Selection.Column).Find("*", , xlValues, , xlByRows, xlPrevious).Row
    
        For i = LastRow To 2 Step -1
            If Cells(i, Selection.Column) <> Cells(i - 1, Selection.Column) Then Rows(i).Insert
        Next i
    
        Application.ScreenUpdating = True
    End Sub
    Test VBA on a copy of your data (remember you can't normally reverse the action)

    Please follow the forum Rules and Guidelines & please use Code tags around your code i.e. [CODE]your code[/CODE]

    To post a screenshot try one of these links
    MrExcel HTML Maker, RoryA addin (Win & Mac) or Borders-Copy-Paste

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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