Hello,
I am building a dashboard which contains a revenue overview (monthly). The user of the dashboard selects the start month and end month (e.g. January - July). It would then look like this
[table="width: 500, align: center"]
[tr]
[td]SERVICES[/td]
[td]January[/td]
[td]February[/td]
[td]March[/td]
[td]April[/td]
[td]May[/td]
[td]June[/td]
[td]July[/td]
[td]Total[/td]
[/tr]
[tr]
[td]Product1[/td]
[td]152345[/td]
[td]435156[/td]
[td]549141[/td]
[td]234581[/td]
[td]645127[/td]
[td]512487[/td]
[td]157481[/td]
[td]sum[/td]
[/tr]
[tr]
[td]Product2[/td]
[td]32457[/td]
[td]38754[/td]
[td]64517[/td]
[td]54781[/td]
[td]51204[/td]
[td]54178[/td]
[td]48761[/td]
[td]sum[/td]
[/tr]
[/table]
I am trying to find a VBA code to calculate the sum per product. This range per product always starts with a fixed cell and has to end with the cell of the last column within the same row. However the last column can change (could be any month of the year).
I already found a way to capture the last column number using this:
But I got stuck creating a WorksheetFunction.Sum that will calculate the sum per product for all months in each row (with a variable end month).
Does any one would have any advise?
Thank you in advance!
I am building a dashboard which contains a revenue overview (monthly). The user of the dashboard selects the start month and end month (e.g. January - July). It would then look like this
[table="width: 500, align: center"]
[tr]
[td]SERVICES[/td]
[td]January[/td]
[td]February[/td]
[td]March[/td]
[td]April[/td]
[td]May[/td]
[td]June[/td]
[td]July[/td]
[td]Total[/td]
[/tr]
[tr]
[td]Product1[/td]
[td]152345[/td]
[td]435156[/td]
[td]549141[/td]
[td]234581[/td]
[td]645127[/td]
[td]512487[/td]
[td]157481[/td]
[td]sum[/td]
[/tr]
[tr]
[td]Product2[/td]
[td]32457[/td]
[td]38754[/td]
[td]64517[/td]
[td]54781[/td]
[td]51204[/td]
[td]54178[/td]
[td]48761[/td]
[td]sum[/td]
[/tr]
[/table]
I am trying to find a VBA code to calculate the sum per product. This range per product always starts with a fixed cell and has to end with the cell of the last column within the same row. However the last column can change (could be any month of the year).
I already found a way to capture the last column number using this:
PHP:
Dim LastCol As Long
With ActiveSheet
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
End With
Cells(2, LastCol).Value = WorksheetFunction.Sum(Cells(2,2) ?????)
But I got stuck creating a WorksheetFunction.Sum that will calculate the sum per product for all months in each row (with a variable end month).
Does any one would have any advise?
Thank you in advance!