PDA

View Full Version : [SOLVED:] VBA to use Selection.Address in a formula



simora
08-05-2021, 01:32 AM
I have this bit of code


Range("H" & iRow).Resize(cRng, 12).Select
addr = Selection.Address


I am trying to get this formula into a cell using VBA
=ColorFunction($IE$1,$H2:$S3,TRUE)

So that it says


ActiveSheet.Range("IG2").Formula = "=ColorFunction($IE$1,$H2:$S3,TRUE)”

$ID$1, $IE$1, $IF$1 is from the color that we’re looking for.
I may put the selected value into a variable.
addr is $H2:$S3 BUT $H2:$S3 is also located in cell HY1

How do I code this "=ColorFunction($IE$1 ,addr,TRUE)”

arnelgp
08-05-2021, 04:29 AM
=ColorFunction($IE$1 ," & addr & ",TRUE)”

simora
08-05-2021, 10:30 AM
..

simora
08-05-2021, 10:31 AM
arnelgp (http://www.vbaexpress.com/forum/member.php?74556-arnelgp): Thanks.
It works.



addr = Selection.Address
ActiveSheet.Range("IG2").Formula = "=ColorFunction($IE$1 ," & addr & ",TRUE)"