Results 1 to 5 of 5

Thread: [Excel] adding a row to spreadsheet want to update my code

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    2

    [Excel] adding a row to spreadsheet want to update my code

    Hi all

    I'm not confident with VBA as yet and have simply been creating macro's and then found the need to edit them, so am gradually exploring VBA and what can be done with it.

    I currently have a spreadsheet with column A containing staff names. I then have calculations set up to track their working patterns.
    I have created a macro that inserts a column at column f and then updates all of my formulae accordingly for example range (d3:d123).

    However, when I add or remove staff this changes the final row reference by one or two digits and I want to know if there is a way that my code re-written to update automatically and amend my range:

    here is my code, highlighted are the bits that are variable:
    Code:
     
        Columns("F:F").Select
        Selection.Insert Shift:=xlToRight
        Range("G2").Select
        Selection.AutoFill Destination:=Range("F2:G2"), Type:=xlFillDefault
        Range("F2:G2").Select
        Columns("F:F").EntireColumn.AutoFit
          
        Range("B4").Select
        ActiveCell.FormulaR1C1 = "=COUNTA(RC[4]:RC[17])"
        Range("B4").Select
        Selection.AutoFill Destination:=Range("B4:B123"), Type:=xlFillDefault
        Range("B4:B123").Select
           Range("D4").Select
        ActiveCell.FormulaR1C1 = "=COUNTA(RC[2]:RC[29])"
        Range("D4").Select
        Selection.AutoFill Destination:=Range("D4:D123"), Type:=xlFillDefault
        Range("D4:D123").Select
        
        Range("H2").Select
        Selection.AutoFill Destination:=Range("G2:H2"), Type:=xlFillDefault
        Range("G2:H2").Select
        Columns("G:G").Select
        Selection.Copy
        Columns("F:F").Select
        
        Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False
        Application.CutCopyMode = False
         Range("G124").Select
        Application.CutCopyMode = False
        Selection.AutoFill Destination:=Range("F124:G124"), Type:=xlFillDefault
        Range("F124:G124").Select
           Range("F4").Select
    End Sub
    Thank you all in advance

    ETA a bit of gratitude goes a long way
    Last edited by Hack; Nov 3rd, 2008 at 11:40 AM. Reason: Added Code Tags

Posting Permissions

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



Click Here to Expand Forum to Full Width