+ Reply to Thread
Results 1 to 2 of 2

Auto-filling formulas across multiple sheets

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-15-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    141

    Auto-filling formulas across multiple sheets

    Hi, everyone,

    I have a massive document with 1000+ sheets. Each sheet has "year" columns (2009, 2010, 2011, and 2012), and varying numbers of rows (anywhere from 1 to about 100), and I'd like to add columns to each sheet showing the year vs. year % difference.

    The attached Excel document has a before/after example. Any VBA guidance here would be greatly appreciated.

    Excel Percent Diff Example.xlsxExcel Percent Diff Example.xlsx

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Auto-filling formulas across multiple sheets

    The BEFORE sheet already has empty columns between the columns, so all you need is help inserting the formulas?

    This should do it:
    Option Explicit
    
    Sub AddFormulas()
    Dim ws As Worksheet, LR As Long, col As Long
    
    On Error Resume Next
    For Each ws In Worksheets
        LR = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
        For col = 4 To 10 Step 3
            With ws.Cells(2, col).Resize(LR - 1)
                .NumberFormat = "0%"
                .FormulaR1C1 = "=RC[-1]/RC[2]-1"
            End With
        Next col
    Next ws
    
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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