ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Named formula VBA insert error (https://www.excelbanter.com/excel-programming/374802-named-formula-vba-insert-error.html)

[email protected]

Named formula VBA insert error
 
I'm not sure if this a Worksheet Function issue or a VBA issue
because it involves both...

I need to paste a named formula, using VBA into a vertical range of
cells. I need the formula to add the value of the previous cell (the
cell above the current cell) the result of a separate calculation in
the formula.

The VBA code is working and pasts the formula where I need it.

The "separate calculation" is working

In troubleshooting my problem I found:

If I write the formula directly into the first cell and then copy and
paste it manually into the rest of the range everything works fine.

Formula as written in A114 and also in the "Refers To:" block for
Name "BinSizeForm2"
=A113+INDIRECT($C$114&"BinSize"&$D$114)

As pasted in subsequent cells:
=A114+INDIRECT($C$114&"BinSize"&$D$114)
=A115+INDIRECT($C$114&"BinSize"&$D$114)
=A116+INDIRECT($C$114&"BinSize"&$D$114)
And so on... which works perfect

Putting "=BinSizeForm2" in each cell returns the correct results
also.

The problem occurs when the name is written to the range cells using
VBA; all cells end up with the same value (formula):
=Htestc!A113+INDIRECT(Htestc!$C$114&"BinSize"&Htes tc!$D$114)

Every cell starts with A113 instead of the previous cell reference.


Help.


[email protected]

Named formula VBA insert error
 
this should have read:
I need the formula to add the value of the previous cell (the
cell above the current cell) TO the result of a separate calculation in
the formula.

:O


wrote:
I'm not sure if this a Worksheet Function issue or a VBA issue
because it involves both...

I need to paste a named formula, using VBA into a vertical range of
cells. I need the formula to add the value of the previous cell (the
cell above the current cell) the result of a separate calculation in
the formula.

The VBA code is working and pasts the formula where I need it.

The "separate calculation" is working

In troubleshooting my problem I found:

If I write the formula directly into the first cell and then copy and
paste it manually into the rest of the range everything works fine.

Formula as written in A114 and also in the "Refers To:" block for
Name "BinSizeForm2"
=A113+INDIRECT($C$114&"BinSize"&$D$114)

As pasted in subsequent cells:
=A114+INDIRECT($C$114&"BinSize"&$D$114)
=A115+INDIRECT($C$114&"BinSize"&$D$114)
=A116+INDIRECT($C$114&"BinSize"&$D$114)
And so on... which works perfect

Putting "=BinSizeForm2" in each cell returns the correct results
also.

The problem occurs when the name is written to the range cells using
VBA; all cells end up with the same value (formula):
=Htestc!A113+INDIRECT(Htestc!$C$114&"BinSize"&Htes tc!$D$114)

Every cell starts with A113 instead of the previous cell reference.


Help.




All times are GMT +1. The time now is 01:37 PM.

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