Results 1 to 5 of 5

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

Threaded View

  1. #3
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

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

    Sarah, I have edited what you posted to what should be a working macro. However, it is still using some static offsets "RC[2]:RC[29]" and I don't know what these are referring to.

    I can see that you are just using the record macro feature and checking it out. Have you had any programming experience before now?

    Code:
    Sub lkjslkfjd()
    
        Dim EndRange As Range
        Dim LastRow As String
        Dim s As String
        
        Columns("F:F").Select
        
        'This will return the last row used.
        'ASSUMES: All values are filled in starting with row 1 and
        '         there are no empty cells all the way to the end.
        Set EndRange = Selection.End(xlDown)
        LastRow = CStr(EndRange.Row)
        
        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])"
        
        s = Replace("B4:B?", "?", LastRow)
        Selection.AutoFill Destination:=Range(s), Type:=xlFillDefault
    
        Range("D4").Select
        ActiveCell.FormulaR1C1 = "=COUNTA(RC[2]:RC[29])"
        
        s = Replace("D4:D?", "?", LastRow)
        Selection.AutoFill Destination:=Range(s), Type:=xlFillDefault
        
        Range("H2").Select
        Selection.AutoFill Destination:=Range("G2:H2"), Type:=xlFillDefault
        
        Columns("G:G").Select
        Selection.Copy
        Columns("F:F").Select
        Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False
        Application.CutCopyMode = False
        
        Range("G" & LastRow).Select
        s = Replace("F?:G?", "?", LastRow)
        Selection.AutoFill Destination:=Range(s), Type:=xlFillDefault
        Range("F4").Select
    End Sub
    Last edited by dmaruca; Nov 3rd, 2008 at 12:24 PM.

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