+ Reply to Thread
Results 1 to 6 of 6

MACRO to Insert row in 'D' col after name changed.

Hybrid View

  1. #1
    Forum Contributor visha_1984's Avatar
    Join Date
    11-27-2012
    Location
    Pune,India
    MS-Off Ver
    Excel 2013
    Posts
    309

    MACRO to Insert row in 'D' col after name changed.

    Hi,Team

    I need macro to insert blank row in D col after name changed for specific range or from specific row
    I have attached sample file, Below is macro code which is used for inserting blank row.

    Sub InsertBRow()
        Dim iRow    As Long
    
        iRow = 3
        Do
            With Cells(iRow, "D")
                If IsEmpty(.Value) Then Exit Do
                If .Offset(-1).Value <> .Value Then
                    .EntireRow.Insert
                    iRow = iRow + 2
                Else
                    iRow = iRow + 1
                End If
            End With
        Loop
    End Sub
    Thanks in advance
    Attached Files Attached Files
    Happy to Help

    VISHA

    Click *, if the suggestion helps you!
    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>> "Mark your thread as Solved"

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: MACRO to Insert row in 'D' col after name changed.

    Hi visha_1984, try the following:
    Sub InsertRows()
        
        Dim ws1 As Worksheet
        Dim dRng As Range
        Dim oC As Range
        
        Application.ScreenUpdating = False
        Set ws1 = Worksheets("Sheet1")
        Set dRng = ws1.Range(ws1.Cells(1, 4), ws1.Cells(ws1.Rows.Count, 4).End(xlUp))
        For Each oC In dRng
            If oC.Offset(1, 0).Value <> oC.Value And oC.Value <> "" Then
                oC.Offset(1, 0).EntireRow.Insert xlUp
            End If
        Next oC
        Application.ScreenUpdating = True
        
    End Sub
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Forum Contributor visha_1984's Avatar
    Join Date
    11-27-2012
    Location
    Pune,India
    MS-Off Ver
    Excel 2013
    Posts
    309

    Re: MACRO to Insert row in 'D' col after name changed.

    Hi Mordred

    Thanks for reply

    your code is working perfectly but it inserts blank row in whole sheet again which are allready been inserted , But i want macro to insert row which are not inserted in the same col before.

  4. #4
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: MACRO to Insert row in 'D' col after name changed.

    Sorry, the following should now do the trick
    Sub InsertRows()
        
        Dim ws1 As Worksheet
        Dim dRng As Range
        Dim oC As Range
        
        Application.ScreenUpdating = False
        Set ws1 = Worksheets("Sheet1")
        Set dRng = ws1.Range(ws1.Cells(1, 4), ws1.Cells(ws1.Rows.Count, 4).End(xlUp))
        For Each oC In dRng
            If oC.Offset(1, 0).Value <> oC.Value And oC.Offset(1, 0).Value <> "" And oC.Value <> "" Then
                oC.Offset(1, 0).EntireRow.Insert xlUp
            End If
        Next oC
        Application.ScreenUpdating = True
        
    End Sub

  5. #5
    Forum Contributor visha_1984's Avatar
    Join Date
    11-27-2012
    Location
    Pune,India
    MS-Off Ver
    Excel 2013
    Posts
    309

    Re: MACRO to Insert row in 'D' col after name changed.

    Perfect.

    Thank u very much Mordred

    Good Day

  6. #6
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: MACRO to Insert row in 'D' col after name changed.

    You are most welcome and have a great day too!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Excel 2007 : Insert DATE if any Cell in Row changed
    By varocketry in forum Excel General
    Replies: 4
    Last Post: 12-03-2012, 06:30 PM
  2. Insert new columns when the value in the column changed
    By mridzuani in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-18-2011, 04:14 AM
  3. Insert Formula if cell is changed from blank
    By buffalotom99 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-24-2009, 07:54 AM
  4. Insert date when adjacent cell changed
    By speakers_86 in forum Excel General
    Replies: 0
    Last Post: 10-02-2006, 02:54 PM
  5. [SOLVED] Insert function changed
    By EZDO Bob in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-08-2005, 12:06 PM

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