Shippwreck
Programmer
Hi,
I have a set of worksheets and i need to sum the same cell in each of them together. I was at first using THREED that i found in an excel add in on the net but then realised that when i distribute the file anyone without this add in wont be able to use it properly and seeings as the users are not always as literate as me with excel i can't really provide them with the add in and expect them to install it properly. Anyway i decided to try to write my own version from scratch. Below is how far i have got:
Function AggregateFN(celladdress)
Startsheet = Worksheets("Start").Index
Endsheet = Worksheets("End").Index
Startsheet = Startsheet + 1
Do Until Startsheet = Endsheet
Worksheets(Startsheet).Activate
Cellvalue1 = ActiveSheet.Range(celladdress).Value
Cellvalue2 = Cellvalue1 + Cellvalue2
Startsheet = Startsheet + 1
Loop
AggregateFN = Cellvalue2
End Function
The idea is that i have a workbook with lots of worksheets and i only want to sum certain sheets but that i want to be able to add more sheets if necessary and for these to be included in the sum without any extra coding. So like THREED i put in a start and end sheet either side of the sheets i wish to sum. I then have another sheet outside these that will contain the summed figures.
The idea was to make it a function with the address of the cell to be summed from each each sheet as the input. This code will run all the way through working properly if you type:
=AggregateFN("D8")
except that it gives a value of the cell in D8 in the worksheet that it is in timesd by however many sheets in between the start and end sheets which is not correct. I think the problem is with the line that activates a different sheet as it doesn't change sheets at all but i don't know whats wrong. Additionally if you omit the quotation marks however it stops at:
Cellvalue1 = ActiveSheet.Range(celladdress).Value
because it is passing the value in that cell in the current sheet.
Can someone please help me with making this work as i am now totally stuck.
Thanks in advance, this is sending me crazy!!!
Matt
I have a set of worksheets and i need to sum the same cell in each of them together. I was at first using THREED that i found in an excel add in on the net but then realised that when i distribute the file anyone without this add in wont be able to use it properly and seeings as the users are not always as literate as me with excel i can't really provide them with the add in and expect them to install it properly. Anyway i decided to try to write my own version from scratch. Below is how far i have got:
Function AggregateFN(celladdress)
Startsheet = Worksheets("Start").Index
Endsheet = Worksheets("End").Index
Startsheet = Startsheet + 1
Do Until Startsheet = Endsheet
Worksheets(Startsheet).Activate
Cellvalue1 = ActiveSheet.Range(celladdress).Value
Cellvalue2 = Cellvalue1 + Cellvalue2
Startsheet = Startsheet + 1
Loop
AggregateFN = Cellvalue2
End Function
The idea is that i have a workbook with lots of worksheets and i only want to sum certain sheets but that i want to be able to add more sheets if necessary and for these to be included in the sum without any extra coding. So like THREED i put in a start and end sheet either side of the sheets i wish to sum. I then have another sheet outside these that will contain the summed figures.
The idea was to make it a function with the address of the cell to be summed from each each sheet as the input. This code will run all the way through working properly if you type:
=AggregateFN("D8")
except that it gives a value of the cell in D8 in the worksheet that it is in timesd by however many sheets in between the start and end sheets which is not correct. I think the problem is with the line that activates a different sheet as it doesn't change sheets at all but i don't know whats wrong. Additionally if you omit the quotation marks however it stops at:
Cellvalue1 = ActiveSheet.Range(celladdress).Value
because it is passing the value in that cell in the current sheet.
Can someone please help me with making this work as i am now totally stuck.
Thanks in advance, this is sending me crazy!!!
Matt