Get Formula in Cell rather than Value

stephen antoine

Board Regular
Joined
Jun 4, 2008
Messages
128
Good evening,

I have a bit of code that uses variables to select a specific cell and then performs a calculation and dumps the value in the active cell...The problem is that I want the formula to be in the cell not the value...

The code I used is as follows:

Code:
ActiveCell.Formula = Cells(FinalRow + 2, CYSales).Value / ActiveCell.Offset(-5,0)

Where FinalRow and CYSales are my row and column variable...

My code works, but it dumps the value in the cell, I want the formula..

Can someone please help? :confused:
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
ActiveCell.Formula = "=" & Cells(FinalRow + 2, CYSales).Value & "/" & ActiveCell.Offset(-5, 0)
 
Upvote 0
Thanks, that seemed to work partially, because now instead of a single value it's the value of the first cell divided by the value of the second cell, like the following:

=50/10

Where 50 is in cell C35 for instance and 10 is in cell E40

But I'm trying to get the cell reference to show up as well so the result would be something like this:

=C35/E40

Is that possible?
 
Upvote 0
ActiveCell.Formula = "=" & Cells(FinalRow + 2, CYSales).Address(0,0) & "/" & ActiveCell.Offset(-5, 0).Address(0,0)
 
Upvote 0

Forum statistics

Threads
1,214,650
Messages
6,120,734
Members
448,987
Latest member
marion_davis

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