How to get a cell reference in conditional formatting formula using VBA

Yousif13399

New Member
Joined
Apr 10, 2023
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Hello
Os:windows 11/excel 2016

I need to highlight the values that are equal to D1 in the range of A1 to A2, but I need to do it in a Macro VBA and I need to use cell reference

Screenshot 2023-04-11 045934.png


I recorded the process using record a macro and this is the original code:

Screenshot 2023-04-11 051159.png


So
1st row: I changed the range to: Activecell,Activecell.offset(1,0) (this will select the current cell and the one below it as the range for the macro and this works perfectly
3rd row: I changed the formulal equal to: Activecell.offset(0,3)

Screenshot 2023-04-11 051345.png


But instead of excel writing the cell reference in the formula it's copying the exact words of Activecell.offset(0,3)

Screenshot 2023-04-11 051448.png



how can I get $D$3 instead of Activecell.offset(0,3)?
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
If you changed your original code to:
VBA Code:
Formula1:="=$D$3"

does that not give you what you want?
 
Upvote 0
If you changed your original code to:
VBA Code:
Formula1:="=$D$3"

does that not give you what you want?
It does for one line, but in my project I have thousands of lines so I just want to go to the corresponding row and initiate the macro, keeping D3 in the macro will always go to cell D3.
 
Upvote 0
try
VBA Code:
Formula1 = ActiveCell.Offset(, 3).Address
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,376
Members
449,080
Latest member
Armadillos

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