Totaling columns

J

John

I was so impressed with the wonderful responses and spot on answers to my
first question on this site I thought I would give this one a try. I did try
to research to find this on the site, but perhaps I am wording my search
incorrectly.
My question is: On my download I run a macro that I have set up do
calculations on my worksheet.
1.Each time the report is ran it would have varying information and
varying numer of lines.
For each run of the report the columns below would a have the following in
common, but again each run would have a varying amount of rows)
2. Col A will have some blanks in the cells
3. Col B, C, D & E will have the same number of rows (no blanks in cells)
4. Col G, H & I will have the same number of rows (no blanks in cells)
5. Col K, L, M, & N will have the same number of rows (no blanks in cells)
6. Col P,Q,R,S & T will have the same number of rows (no blanks in cells)

· I would like to go to the last cell with data of each column individually
(E, I, N, & Q) and put the totals on the line below. (totals will not be on
the same row).
· Also as an alternative, I may like the totals all on the same row (find
the last cell with data, go to the next row below and total those columns all
on the same row.
· Whew, I think that’s about all.
Thanks for trying to solve this.
John
 
F

FSt1

hi
something like this might work for you..
Dim lr As Long
lr = [E2].End(xlDown).Row
[E2].End(xlDown).Offset(1, 0).Formula = "=SUM(E2:E" & lr & ")"

you would only need to dim lr once but would need to re assign the row value
for each formula since you say they are all different. the above is for E
column

lr = [I2].End(xlDown).Row
[I2].End(xlDown).Offset(1, 0).Formula = "=SUM(I2:I" & lr & ")"

the above would be for I column. and you would need the two lines above for
each column that you wanted to put the formula in. just adjust the cell
references.
the above assumes no blanks in column. if you ever do have blanks in the
data, you can find the last row from the bottom ie...

lr = [E65000].End(xlup).Row
or
lr = cells(rows.count, "E").end(xlup).row

regards
FSt1
 
J

John

Thank you that works perfectly. I appoligize, I did forget to include that it
is possible that there would be no data to total in column I, N, & Q. Is
there a way to accomodate for that scenerio so it does not error out?
John


FSt1 said:
hi
something like this might work for you..
Dim lr As Long
lr = [E2].End(xlDown).Row
[E2].End(xlDown).Offset(1, 0).Formula = "=SUM(E2:E" & lr & ")"

you would only need to dim lr once but would need to re assign the row value
for each formula since you say they are all different. the above is for E
column

lr = [I2].End(xlDown).Row
[I2].End(xlDown).Offset(1, 0).Formula = "=SUM(I2:I" & lr & ")"

the above would be for I column. and you would need the two lines above for
each column that you wanted to put the formula in. just adjust the cell
references.
the above assumes no blanks in column. if you ever do have blanks in the
data, you can find the last row from the bottom ie...

lr = [E65000].End(xlup).Row
or
lr = cells(rows.count, "E").end(xlup).row

regards
FSt1

John said:
I was so impressed with the wonderful responses and spot on answers to my
first question on this site I thought I would give this one a try. I did try
to research to find this on the site, but perhaps I am wording my search
incorrectly.
My question is: On my download I run a macro that I have set up do
calculations on my worksheet.
1.Each time the report is ran it would have varying information and
varying numer of lines.
For each run of the report the columns below would a have the following in
common, but again each run would have a varying amount of rows)
2. Col A will have some blanks in the cells
3. Col B, C, D & E will have the same number of rows (no blanks in cells)
4. Col G, H & I will have the same number of rows (no blanks in cells)
5. Col K, L, M, & N will have the same number of rows (no blanks in cells)
6. Col P,Q,R,S & T will have the same number of rows (no blanks in cells)

· I would like to go to the last cell with data of each column individually
(E, I, N, & Q) and put the totals on the line below. (totals will not be on
the same row).
· Also as an alternative, I may like the totals all on the same row (find
the last cell with data, go to the next row below and total those columns all
on the same row.
· Whew, I think that’s about all.
Thanks for trying to solve this.
John
 
F

FSt1

hi
i covered that scenerio with comments at the bottom of my post. simply
substitute the line of code i suppied.

regards
FSt1

John said:
Thank you that works perfectly. I appoligize, I did forget to include that it
is possible that there would be no data to total in column I, N, & Q. Is
there a way to accomodate for that scenerio so it does not error out?
John


FSt1 said:
hi
something like this might work for you..
Dim lr As Long
lr = [E2].End(xlDown).Row
[E2].End(xlDown).Offset(1, 0).Formula = "=SUM(E2:E" & lr & ")"

you would only need to dim lr once but would need to re assign the row value
for each formula since you say they are all different. the above is for E
column

lr = [I2].End(xlDown).Row
[I2].End(xlDown).Offset(1, 0).Formula = "=SUM(I2:I" & lr & ")"

the above would be for I column. and you would need the two lines above for
each column that you wanted to put the formula in. just adjust the cell
references.
the above assumes no blanks in column. if you ever do have blanks in the
data, you can find the last row from the bottom ie...

lr = [E65000].End(xlup).Row
or
lr = cells(rows.count, "E").end(xlup).row

regards
FSt1

John said:
I was so impressed with the wonderful responses and spot on answers to my
first question on this site I thought I would give this one a try. I did try
to research to find this on the site, but perhaps I am wording my search
incorrectly.
My question is: On my download I run a macro that I have set up do
calculations on my worksheet.
1.Each time the report is ran it would have varying information and
varying numer of lines.
For each run of the report the columns below would a have the following in
common, but again each run would have a varying amount of rows)
2. Col A will have some blanks in the cells
3. Col B, C, D & E will have the same number of rows (no blanks in cells)
4. Col G, H & I will have the same number of rows (no blanks in cells)
5. Col K, L, M, & N will have the same number of rows (no blanks in cells)
6. Col P,Q,R,S & T will have the same number of rows (no blanks in cells)

· I would like to go to the last cell with data of each column individually
(E, I, N, & Q) and put the totals on the line below. (totals will not be on
the same row).
· Also as an alternative, I may like the totals all on the same row (find
the last cell with data, go to the next row below and total those columns all
on the same row.
· Whew, I think that’s about all.
Thanks for trying to solve this.
John
 
J

John

Sorry, Yes that works and will save me alot of time, Thank you very much
--
John


FSt1 said:
hi
i covered that scenerio with comments at the bottom of my post. simply
substitute the line of code i suppied.

regards
FSt1

John said:
Thank you that works perfectly. I appoligize, I did forget to include that it
is possible that there would be no data to total in column I, N, & Q. Is
there a way to accomodate for that scenerio so it does not error out?
John


FSt1 said:
hi
something like this might work for you..
Dim lr As Long
lr = [E2].End(xlDown).Row
[E2].End(xlDown).Offset(1, 0).Formula = "=SUM(E2:E" & lr & ")"

you would only need to dim lr once but would need to re assign the row value
for each formula since you say they are all different. the above is for E
column

lr = [I2].End(xlDown).Row
[I2].End(xlDown).Offset(1, 0).Formula = "=SUM(I2:I" & lr & ")"

the above would be for I column. and you would need the two lines above for
each column that you wanted to put the formula in. just adjust the cell
references.
the above assumes no blanks in column. if you ever do have blanks in the
data, you can find the last row from the bottom ie...

lr = [E65000].End(xlup).Row
or
lr = cells(rows.count, "E").end(xlup).row

regards
FSt1

:

I was so impressed with the wonderful responses and spot on answers to my
first question on this site I thought I would give this one a try. I did try
to research to find this on the site, but perhaps I am wording my search
incorrectly.
My question is: On my download I run a macro that I have set up do
calculations on my worksheet.
1.Each time the report is ran it would have varying information and
varying numer of lines.
For each run of the report the columns below would a have the following in
common, but again each run would have a varying amount of rows)
2. Col A will have some blanks in the cells
3. Col B, C, D & E will have the same number of rows (no blanks in cells)
4. Col G, H & I will have the same number of rows (no blanks in cells)
5. Col K, L, M, & N will have the same number of rows (no blanks in cells)
6. Col P,Q,R,S & T will have the same number of rows (no blanks in cells)

· I would like to go to the last cell with data of each column individually
(E, I, N, & Q) and put the totals on the line below. (totals will not be on
the same row).
· Also as an alternative, I may like the totals all on the same row (find
the last cell with data, go to the next row below and total those columns all
on the same row.
· Whew, I think that’s about all.
Thanks for trying to solve this.
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top