If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Totaling columns
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 |
#2
|
|||
|
|||
Totaling columns
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" wrote: 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 |
#3
|
|||
|
|||
Totaling columns
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" wrote: 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" wrote: 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 |
#4
|
|||
|
|||
Totaling columns
hi
i covered that scenerio with comments at the bottom of my post. simply substitute the line of code i suppied. regards FSt1 "John" wrote: 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" wrote: 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" wrote: 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 |
#5
|
|||
|
|||
Totaling columns
Sorry, Yes that works and will save me alot of time, Thank you very much
-- John "FSt1" wrote: hi i covered that scenerio with comments at the bottom of my post. simply substitute the line of code i suppied. regards FSt1 "John" wrote: 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" wrote: 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" wrote: 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 |
Thread Tools | |
Display Modes | |
|
|