ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sum Forula using variables (https://www.excelbanter.com/excel-programming/416520-sum-forula-using-variables.html)

Sue

Sum Forula using variables
 
I have a position where I want a total. I have cells (Lower and Upper) that I
want to sum between. I have checked the addresses of these range variables
and they are correct (and the data between them is numeric). But I can not
seem to get it right in the "sum" formula. I have tried using using the range
variables, the address (string) variables, I have put quotes all over the
place - Help!!

'Record position for subtotal
Set SubPos = ActiveCell
SubPosAddress = SubPos.Address

'Coordinates of lower cell in total
Set LowerCell = ActiveCell.Offset(0, -1)
LowerAddress = LowerCell.Address

ActiveCell.End(xlUp).Select

'Coordinates of upper cell in total
Set UpperCell = ActiveCell.Offset(1, -1)
UpperAddress = UpperCell.Address

'Return to marked position
SubPos.Select

** ActiveCell.Formula = "=Sum(Lowercell : Uppercell)"
This line is rubbish but it is the idea I want.


Stefi

Sum Forula using variables
 
ActiveCell.Formula = "=Sum(" & LowerAddress & ":" & UpperAddress & ")"

Regards,
Stefi

€˛Sue€¯ ezt Ć*rta:

I have a position where I want a total. I have cells (Lower and Upper) that I
want to sum between. I have checked the addresses of these range variables
and they are correct (and the data between them is numeric). But I can not
seem to get it right in the "sum" formula. I have tried using using the range
variables, the address (string) variables, I have put quotes all over the
place - Help!!

'Record position for subtotal
Set SubPos = ActiveCell
SubPosAddress = SubPos.Address

'Coordinates of lower cell in total
Set LowerCell = ActiveCell.Offset(0, -1)
LowerAddress = LowerCell.Address

ActiveCell.End(xlUp).Select

'Coordinates of upper cell in total
Set UpperCell = ActiveCell.Offset(1, -1)
UpperAddress = UpperCell.Address

'Return to marked position
SubPos.Select

** ActiveCell.Formula = "=Sum(Lowercell : Uppercell)"
This line is rubbish but it is the idea I want.


Sue

Sum Forula using variables
 
Thanks, that solves my problem. I did try many & and " but when I had some
right I always had something wrong. Thanks so much.

"Stefi" wrote:

ActiveCell.Formula = "=Sum(" & LowerAddress & ":" & UpperAddress & ")"

Regards,
Stefi

€˛Sue€¯ ezt Ć*rta:

I have a position where I want a total. I have cells (Lower and Upper) that I
want to sum between. I have checked the addresses of these range variables
and they are correct (and the data between them is numeric). But I can not
seem to get it right in the "sum" formula. I have tried using using the range
variables, the address (string) variables, I have put quotes all over the
place - Help!!

'Record position for subtotal
Set SubPos = ActiveCell
SubPosAddress = SubPos.Address

'Coordinates of lower cell in total
Set LowerCell = ActiveCell.Offset(0, -1)
LowerAddress = LowerCell.Address

ActiveCell.End(xlUp).Select

'Coordinates of upper cell in total
Set UpperCell = ActiveCell.Offset(1, -1)
UpperAddress = UpperCell.Address

'Return to marked position
SubPos.Select

** ActiveCell.Formula = "=Sum(Lowercell : Uppercell)"
This line is rubbish but it is the idea I want.


Stefi

Sum Forula using variables
 
You are welcome! Thanks for the feedback!
Stefi

€˛Sue€¯ ezt Ć*rta:

Thanks, that solves my problem. I did try many & and " but when I had some
right I always had something wrong. Thanks so much.

"Stefi" wrote:

ActiveCell.Formula = "=Sum(" & LowerAddress & ":" & UpperAddress & ")"

Regards,
Stefi

€˛Sue€¯ ezt Ć*rta:

I have a position where I want a total. I have cells (Lower and Upper) that I
want to sum between. I have checked the addresses of these range variables
and they are correct (and the data between them is numeric). But I can not
seem to get it right in the "sum" formula. I have tried using using the range
variables, the address (string) variables, I have put quotes all over the
place - Help!!

'Record position for subtotal
Set SubPos = ActiveCell
SubPosAddress = SubPos.Address

'Coordinates of lower cell in total
Set LowerCell = ActiveCell.Offset(0, -1)
LowerAddress = LowerCell.Address

ActiveCell.End(xlUp).Select

'Coordinates of upper cell in total
Set UpperCell = ActiveCell.Offset(1, -1)
UpperAddress = UpperCell.Address

'Return to marked position
SubPos.Select

** ActiveCell.Formula = "=Sum(Lowercell : Uppercell)"
This line is rubbish but it is the idea I want.



All times are GMT +1. The time now is 05:30 PM.

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