R1C1 and named ranges

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
721
Office Version
  1. 2016
Platform
  1. Windows
After quite a bit of trial and error, I've come to realize when using R1C1 it isn't as simple as I had thought.

Fluff was kind of enough to show me the following:
VBA Code:
        Set rng1 = Range(Cells(5, 10), Cells(LR, 10))
        rng1.FormulaR1C1 = "=RC25"

What I'm working on now is how to incorporate worksheet names.

This works fine
VBA Code:
    Dim rng1, rng2 As Range
    Dim mySheet1 As Variant

    mySheet1 = "'Continuous Learning Details'!"
    
    With Sheets("Continuous Learning Details")
        LR = .Cells(.Rows.Count, 1).End(xlUp).Row
        Set rng1 = .Range(.Cells(4, 10), .Cells(LR, 10)) 'Email address
        Set rng2 = .Range(.Cells(4, 12), .Cells(LR, 12)) 'Package
    End With

    Cells(5, 14).Formula = "=COUNTIFS(" & mySheet1 & rng1.Address & ",L5," & mySheet1 & rng2.Address & ",""Q1*"")"

What do I need to do to make the last line work using R1C1?
VBA Code:
    Cells(5, 14).FormulaR1C1 = "=COUNTIFS(" & mySheet1 & rng1.Address & ",RC[-2]," & mySheet1 & rng2.Address & ",""Q1*"")"
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
I think I figured it out -

VBA Code:
    Dim mySheet1, rng1, rng2 As Variant

    mySheet1 = "'Continuous Learning Details'!"
    
    With Sheets("Continuous Learning Details")
        LR = .Cells(.Rows.Count, 1).End(xlUp).Row
        rng1 = "R[-1]C[-4]:R[" & LR & "]C[-4]" 'Emil address
        rng2 = "R[-1]C[-2]:R[" & LR & "]C[-2]" 'Package
    End With

    Cells(5, 14).FormulaR1C1 = "=COUNTIFS(" & mySheet1 & rng1 & ",RC[-2]," & mySheet1 & rng2 & ",""Q1*"")"
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,204
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top