VBA Range absolute formula to relative

Jaymond Flurrie

Well-known Member
Joined
Sep 22, 2008
Messages
919
Office Version
  1. 365
Platform
  1. Windows
This should be pretty simple one. I have in a range a formula that is absolute. I want to turn it to fully relative. What's the smartest option?

So it is:
Excel Formula:
=COUNTIFS(Data!$I$2:$I$586;">0";Data!$EC$2:$EC$586;1)
And I want it as:
Excel Formula:
=COUNTIFS(Data!I2:I586;">0";Data!EC2:EC586;1)

Can I for example use FormulaR1C1 in between? I specifically don't want to make the original input as FormulaR1C1, but I could translate the final result to FormulaR1C1 that I then write to the cell.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Don't really understand what you want, but in VBA say you write say rng as Range:
rng.Address -- you get absolute address like $A$1
rng.Address(0,0) -- you get relative address like A1
 
Upvote 0
Solution
I also don't understand the question. This will insert a fully relative formula:

Range("SomeRange").Formula = "=COUNTIFS(Data!I2:I586,"">0"",Data!EC2:EC586,1)"
 
Upvote 0
Ok, it seems that the actual problem I have is with the address property.

So I can do it with something like:
VBA Code:
    dim myaddress as string
myaddress = Replace(myrange.Offset(, 1).Address, "$", "")
 
Upvote 0
Ok, it seems that the actual problem I have is with the address property.

So I can do it with something like:
VBA Code:
    dim myaddress as string
myaddress = Replace(myrange.Offset(, 1).Address, "$", "")
If you have the code already done that way, then @bebo021999 method is a quick way to re-code

If you want to get the relative address during runtime, then like I said
myaddress = myrange.Offset(,1).Address(0,0)

not need to do replacement. You get the address without $ sign already.
 
Upvote 0
If you have the code already done that way, then @bebo021999 method is a quick way to re-code

If you want to get the relative address during runtime, then like I said
myaddress = myrange.Offset(,1).Address(0,0)

not need to do replacement. You get the address without $ sign already.
Yeah, I think that's a lot better than a custom function :)
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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