Results 1 to 7 of 7

Thread: VBA Code Need it to Copy Formulas

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    452
    Location
    I think figuring out the code would take longer than manual edit for 15 files. However, here are a couple of methods to consider:
    Sub InputFormula()Dim r As Integer, x As Integer, y As Integer, f As String, a As String
    r = 8
    With Worksheets("FY24-Monthly Variance Report")
    For x = 1 To 4
        For y = 1 To 12
            a = Choose(y, "I", "K", "M", "O", "Q", "S", "U", "W", "Y", "AA", "AC", "AE")
            f = "=IF(ISNA(VLOOKUP($C" & r - 1 & ",'FY 23 Actual + Reforecast'!$A$1:$AI$503," & a & "$1,FALSE)),""$0.00"",VLOOKUP($C" & r - 1 & ",'FY 23 Actual + Reforecast'!$A$1:$AI$503," & a & "$1,FALSE))"
            .Range(a & r).Formula = f
        Next
        r = r + 9
    Next
    End With
    End Sub
    
    
    Sub CopyFormula()
    Dim r As Integer, x As Integer, y As Integer, a As String
    With Worksheets("FY24-Monthly Variance Report")
    r = 8
    .Range("I8").Copy
    For x = 1 To 4
        For y = 1 To 12
            a = Choose(y, "I", "K", "M", "O", "Q", "S", "U", "W", "Y", "AA", "AC", "AE")
            .Range(a & r).PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        Next
        r = r + 9
    Next
    End With
    Application.CutCopyMode = False
    End Sub
    Last edited by June7; 11-13-2023 at 12:58 AM.
    How to attach file: Reading and Posting Messages (vbaexpress.com), click Go Advanced below post edit window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Posting Permissions

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