ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Paste VBA formula into cell (https://www.excelbanter.com/excel-programming/424108-paste-vba-formula-into-cell.html)

PJ

Paste VBA formula into cell
 
I have a VBA macro which determines various ranges of cells that need to be
analyzed and assigns the ranges to different values, such as wrkRng. The
line below does partially what I need. It calculates correctly and puts the
value I'm looking for in the specified cell.

Range("B6").Select
ActiveCell.FormulaR1C1 = Evaluate("=COUNTIF(" & wrkRng.Address & ",""1"")")

The problem I have is the macro needs to be run I need to run the macro
before all of the cells have been updated. What I need is for the code to
put the actual formula in the cell so it is recalculated as the cells are
updated later and not the value from when it is initially run.

Since the ranges vary I can't just hard code the formula. But if wrkRng
happened to be D8:I25 at the time the macro was run, I want have this formula
entered into cell B6:

=COUNTIF($D$8:$I$25, "1")

Dave Peterson

Paste VBA formula into cell
 
You have a reply at your earlier post.

PJ wrote:

I have a VBA macro which determines various ranges of cells that need to be
analyzed and assigns the ranges to different values, such as wrkRng. The
line below does partially what I need. It calculates correctly and puts the
value I'm looking for in the specified cell.

Range("B6").Select
ActiveCell.FormulaR1C1 = Evaluate("=COUNTIF(" & wrkRng.Address & ",""1"")")

The problem I have is the macro needs to be run I need to run the macro
before all of the cells have been updated. What I need is for the code to
put the actual formula in the cell so it is recalculated as the cells are
updated later and not the value from when it is initially run.

Since the ranges vary I can't just hard code the formula. But if wrkRng
happened to be D8:I25 at the time the macro was run, I want have this formula
entered into cell B6:

=COUNTIF($D$8:$I$25, "1")


--

Dave Peterson


All times are GMT +1. The time now is 10:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com