+ Reply to Thread
Results 1 to 7 of 7

referencing a column value in R part of a R1C1 formula

Hybrid View

  1. #1
    Registered User
    Join Date
    10-28-2015
    Location
    BFE, USA
    MS-Off Ver
    2010
    Posts
    30

    referencing a column value in R part of a R1C1 formula

    I have a partial formula but am stumped. Can I reference a row with a column value?

    Cells(r, c).FormulaR1C1 = "=IFERROR(((R(beginning 6000 in column Y)C:R(ending 6000 in column Y)C)*0.085)*R2C,0)

    The formula needs to includes the 2019 (column H) numbers of the light green highlighted categories, major account 6000.00.

    The kicker is that some of the individual stores has an extra category which will add 3 more rows to the 6000 category. I can't go backwards because some of the stores would be -28 rows and some would be -25 rows. This is why I was thinking of using a row reference. The far right hand column has the row number and beginning with that row number, every 3rd row value until the end row, including the end row. I put a formula in column J, row 164 for an example of end result.

    I hope this makes sense and any help will be greatly appreciated. Thank you in advance for your assistance.
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: referencing a column value in R part of a R1C1 formula

    If I understand the request then you should be using a SUMIFS() function

    e.g. ij J164.

    Formula: copy to clipboard
    =SUMIFS(J136:J155,H136:H155,2019)*0.085*J2


    And is there a typo since you haven't included J149?
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    10-28-2015
    Location
    BFE, USA
    MS-Off Ver
    2010
    Posts
    30

    Re: referencing a column value in R part of a R1C1 formula

    Richard,
    Yes, there is a typo, it does need to be included. Your formula is okay but as I previously stated, J136 isn't always the starting row.

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,681

    Re: referencing a column value in R part of a R1C1 formula

    You can also create dynamic named ranges:
    Data_Periods ='103'!$J$4:INDEX('103'!$U:$U,COUNT('103'!$D:$D)+3)
    DataYear ='103'!$H$4:INDEX('103'!$H:$H,COUNT('103'!$D:$D)+3)
    MajorAccountID ='103'!$D$4:INDEX('103'!$D:$D,COUNT('103'!$D:$D)+3)
    pro_rated_inflation ='103'!$J$2:$U$2

    Then:
       ActiveCell.FormulaR1C1 = _
            "=SUMIFS(INDEX(Data_Periods,0,COLUMN(R1C[-9])),MajorAccountID,6000,DataYear,RC8)*0.085*INDEX(pro_rated_inflation, COLUMN(R1C[-9]))"
    Last edited by protonLeah; 12-29-2018 at 08:56 PM.
    Ben Van Johnson

  5. #5
    Registered User
    Join Date
    10-28-2015
    Location
    BFE, USA
    MS-Off Ver
    2010
    Posts
    30

    Re: referencing a column value in R part of a R1C1 formula

    I'm not sure I understand correctly. If the ranges have to be created on each sheet then this would virtually be impossible as there are may stores to create all these ranges individually. Is there anyway to achieve this without ranges? I like the sumifs function and I'll work with it to see if I can make this work.

  6. #6
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,681

    Re: referencing a column value in R part of a R1C1 formula

    Or, instead of writing a formula to the cells, calculate and write the sums with the macro:
    Option Explicit
    Sub TaxExpense()
        Dim Acct6000    As Range, _
            AcctDescr   As Range, _
            AcctRec     As Range, _
            ProRateInfl As Range, _
            Counter     As Long, _
            TaxExpRow   As Long, _
            VarianceRow As Long, _
            Accumulator As Double, _
            t0          As Double, _
            TaxYear     As Variant
    
        t0 = Timer
        With Application
            .ScreenUpdating = False ' turn off screen flicker
            .EnableEvents = False ' turn off events
            .DisplayAlerts = False
            .Calculation = xlCalculationManual
            .AskToUpdateLinks = False 'suppress asking for update
        End With
                
        With Range("D:D")
            Set Acct6000 = .Find(6000)
            Counter = WorksheetFunction.CountIf(Range("D:D"), 6000)
            Set Acct6000 = Acct6000.Resize(rowsize:=Counter)
        End With
        
        For Each TaxYear In Array(2018, 2019)
            'find the row to insert PERIOD SUMS
            For Each AcctDescr In Range("G:G")
                If AcctDescr.Value = "PAYROLL TAX EXPENSE" And AcctDescr.Offset(ColumnOffset:=1).Value = TaxYear Then
                    TaxExpRow = AcctDescr.Row
                End If
            
            'find the row to insert variances
                If AcctDescr.Value = "PAYROLL TAX EXPENSE" And AcctDescr.Offset(ColumnOffset:=1).Value = "Variance" Then
                    VarianceRow = AcctDescr.Row
                    Exit For
                End If
            Next AcctDescr
                
            'Total up expenses for each period
            For Each ProRateInfl In Range("J2:U2")
                For Each AcctRec In Acct6000
                    If AcctRec.Offset(ColumnOffset:=4).Value = TaxYear Then
                        Accumulator = Accumulator + AcctRec.Offset(ColumnOffset:=ProRateInfl.Column - AcctRec.Column).Value
                    End If
                Next AcctRec
                
                'format total
                Accumulator = Round(Accumulator * 0.085 * ProRateInfl.Value, 2)
                
                ' ** write to tax expense cells **
                
                Cells(TaxExpRow, ProRateInfl.Column).Value = Accumulator
            Next ProRateInfl
        Next TaxYear
            
        With Application
            .ScreenUpdating = True
            .EnableEvents = True
            .DisplayAlerts = True
            .Calculation = xlCalculationAutomatic
            .AskToUpdateLinks = False
        End With
        MsgBox Round((Timer - t0), 3) & " Sec"
    End Sub

  7. #7
    Registered User
    Join Date
    10-28-2015
    Location
    BFE, USA
    MS-Off Ver
    2010
    Posts
    30

    Re: referencing a column value in R part of a R1C1 formula

    ProtonLeah, works perfect, thanks so much.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Functions, R1C1 and referencing cells
    By dl744 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-11-2016, 08:53 AM
  2. R1C1 formula referencing a .csv wokrbook in 2010
    By SHASPEL in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-21-2013, 01:13 PM
  3. Using Range Name reference as part of R1C1 Formula
    By BEEJAY in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-14-2012, 01:32 PM
  4. Vlookup referencing one column that contains part numbers in both.
    By crafty_girl in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-18-2006, 02:35 PM
  5. referencing ranges using R1C1 format
    By pwermuth in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-08-2005, 10:05 PM
  6. referencing ranges using R1C1 formula:Post a bit more on
    By Danny in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-07-2005, 09:05 PM

Tags for this Thread

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