ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to use an array function in a macro (https://www.excelbanter.com/excel-programming/369162-how-use-array-function-macro.html)

Bharath Rajamani

How to use an array function in a macro
 

Can an array function be executed from a macro, how?

I'd like to construct an array function like

{SUM(IF(A$1:A$500<B1,C1:C500, 0))}

in a macro and call it .. using smthg similar to Application.Worksheetfunction


TIA









Jim Jackson

How to use an array function in a macro
 
The formula can be included in a macro as:

ActiveSheet.Range("D1") = "=SUM(IF(A$1:A$500<B1,C1:C500, 0))"

I don't know if this is what you were looking for.
--
Best wishes,

Jim


"Bharath Rajamani" wrote:


Can an array function be executed from a macro, how?

I'd like to construct an array function like

{SUM(IF(A$1:A$500<B1,C1:C500, 0))}

in a macro and call it .. using smthg similar to Application.Worksheetfunction


TIA









Bharath Rajamani

How to use an array function in a macro
 

Thx Jim, but this is not what I was looking for. I want a cell .. say D1 ..
to contain the result of the array function ...

Cells.formulaR1C1 does not work

The array formula is constructed dynamically in the macro, and I'd like the
macro to execute the array formula, and store the result in a cell




"Jim Jackson" wrote:

The formula can be included in a macro as:

ActiveSheet.Range("D1") = "=SUM(IF(A$1:A$500<B1,C1:C500, 0))"

I don't know if this is what you were looking for.
--
Best wishes,

Jim


"Bharath Rajamani" wrote:


Can an array function be executed from a macro, how?

I'd like to construct an array function like

{SUM(IF(A$1:A$500<B1,C1:C500, 0))}

in a macro and call it .. using smthg similar to Application.Worksheetfunction


TIA









ImpulseBlue

How to use an array function in a macro
 
Heres a short script that will help:
'If you just wanted to output the actual formula to the cell and
execute then:
Sheet1.Range("D1").FormulaArray = "=SUM(IF(A$1:A$500<B1,C1:C500,
0))"

'If you actually want the code to calculate the value and then
output the value:
answer = Evaluate("=SUM(IF(A$1:A$500<B1,C1:C500, 0))")
Sheet1.Range("D1") = answer

Regards

Bharath Rajamani wrote:
Thx Jim, but this is not what I was looking for. I want a cell .. say D1 ..
to contain the result of the array function ...

Cells.formulaR1C1 does not work

The array formula is constructed dynamically in the macro, and I'd like the
macro to execute the array formula, and store the result in a cell




"Jim Jackson" wrote:

The formula can be included in a macro as:

ActiveSheet.Range("D1") = "=SUM(IF(A$1:A$500<B1,C1:C500, 0))"

I don't know if this is what you were looking for.
--
Best wishes,

Jim


"Bharath Rajamani" wrote:


Can an array function be executed from a macro, how?

I'd like to construct an array function like

{SUM(IF(A$1:A$500<B1,C1:C500, 0))}

in a macro and call it .. using smthg similar to Application.Worksheetfunction


TIA











All times are GMT +1. The time now is 04:37 AM.

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