Results 1 to 8 of 8

Thread: Automatically Insert Row

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Senior Member LalitPandey87's Avatar
    Join Date
    Sep 2011
    Posts
    222
    Rep Power
    14
    Step 1:- Create Name Range for Cell B8 and named it 'rngSubTotalPart1'
    Step 2:- Create Name Range for Cell B15 and named it 'rngSubTotalPart2'
    Step 3:- Press Alt + F11 -> Alt + I + M and Paste below code in the module

    Code:
    Const strPart1RangeName                 As String = "rngSubTotalPart1"
    Const strPart2RangeName                 As String = "rngSubTotalPart2"
    
    Sub InsertRowFor_LOCACAO_DO_EQUIPAMENTO()
    
        InsertRow strPart1RangeName
    
    End Sub
    
    Sub InsertRowFor_CESSAO_DE_MAODE_OBRA()
    
        InsertRow strPart2RangeName
    
    End Sub
    
    Sub InsertRow(ByVal strSubTotalRange As String)
    
        Dim wksSht                  As Worksheet
        
        If Application.ScreenUpdating Then Application.ScreenUpdating = False
        
        Set wksSht = ThisWorkbook.Worksheets("Plan1")
        
        With wksSht
            With .Range(strSubTotalRange).Offset(-1)
                If .Value = "" Then
                    MsgBox "Row Already inserted. May be it is not filled.", vbInformation, "Row insert..."
                    GoTo ErlyExit
                End If
                .EntireRow.Copy
                .EntireRow.Insert Shift:=xlDown
                Application.CutCopyMode = False
                If strSubTotalRange = strPart1RangeName Then
                    .Resize(, 5).Value = ""
                    .Offset(, 7).Value = ""
                    .Offset(, 10).Resize(, 2).Clear
                ElseIf strSubTotalRange = strPart2RangeName Then
                    .Resize(, 6).Value = ""
                End If
            End With
        End With
      
    ErlyExit:
        If Not Application.ScreenUpdating Then Application.ScreenUpdating = True
    
    End Sub

    Step 4:- Close This Window (Alt + F4)
    Step 5:- Insert a Shape and right click on it -> click on Assign Macro and assign InsertRowFor_LOCACAO_DO_EQUIPAMENTO macro from the macro list in the pop up window.
    Step 6:- Insert another shape, right click on shape, click on assign macro and assign InsertRowFor_CESSAO_DE_MAODE_OBRA macro to this one.
    Step 7:- Done
    Last edited by LalitPandey87; 12-21-2012 at 09:24 AM.

Similar Threads

  1. Automatically send Birthday E-Mail in Outlook
    By s.ajay88 in forum Outlook Help
    Replies: 2
    Last Post: 03-12-2013, 06:28 PM
  2. Copy Automatically Between Two Worksheets
    By marreco in forum Excel Help
    Replies: 0
    Last Post: 08-27-2012, 04:48 PM
  3. Create Bubble Chart Automatically
    By Excel Fox in forum Download Center
    Replies: 7
    Last Post: 08-12-2012, 10:39 PM
  4. help with after insert event in Access 10
    By richlyn in forum Access Help
    Replies: 9
    Last Post: 03-03-2012, 10:49 PM
  5. Insert 'n' number Rows after any specified row no.
    By LalitPandey87 in forum Excel Help
    Replies: 2
    Last Post: 11-08-2011, 08:59 AM

Posting Permissions

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