ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Syntax using variable in cell Formula (https://www.excelbanter.com/excel-programming/289342-syntax-using-variable-cell-formula.html)

Mike Fogleman

Syntax using variable in cell Formula
 
I want to use a variable in a cell formula like this:
Dim myrng

myrng = Worksheets("Synopsis").Range("A" & Counter + 2)
Range("D1:D" & RowCount - 1).Formula =
"=IF(AND(Totals!$F$1-Data!B1<7,A1=A2,myrng),1,0)"

Because of the " " around the formula, the value of myrng does not appear,
only the word.

TIA, Mike



Tom Ogilvy

Syntax using variable in cell Formula
 
myrng = Worksheets("Synopsis").Range("A" & Counter + 2).Value
Range("D1:D" & RowCount - 1).Formula = _
"=IF(AND(Totals!$F$1-Data!B1<7,A1=A2," & myrng & "),1,0)"



--
Regards,
tom Ogilvy



Mike Fogleman wrote in message
...
I want to use a variable in a cell formula like this:
Dim myrng

myrng = Worksheets("Synopsis").Range("A" & Counter + 2)
Range("D1:D" & RowCount - 1).Formula =
"=IF(AND(Totals!$F$1-Data!B1<7,A1=A2,myrng),1,0)"

Because of the " " around the formula, the value of myrng does not appear,
only the word.

TIA, Mike





Mike Fogleman

Syntax using variable in cell Formula
 
Thanks for the very fast response, Tom. I must have lost that second
ampersand while I was beating around the bush.
"Tom Ogilvy" wrote in message
...
myrng = Worksheets("Synopsis").Range("A" & Counter + 2).Value
Range("D1:D" & RowCount - 1).Formula = _
"=IF(AND(Totals!$F$1-Data!B1<7,A1=A2," & myrng & "),1,0)"



--
Regards,
tom Ogilvy



Mike Fogleman wrote in message
...
I want to use a variable in a cell formula like this:
Dim myrng

myrng = Worksheets("Synopsis").Range("A" & Counter + 2)
Range("D1:D" & RowCount - 1).Formula =
"=IF(AND(Totals!$F$1-Data!B1<7,A1=A2,myrng),1,0)"

Because of the " " around the formula, the value of myrng does not

appear,
only the word.

TIA, Mike








All times are GMT +1. The time now is 03:35 PM.

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