Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use the sum action of the Worksheetfunction method 1

Status
Not open for further replies.

TRHorn

Technical User
Feb 21, 2010
24
US
I'm trying to sum some columns in VBA so I can chart them. I am stuck on how to apply the worksheetfunction method. It's funny because this is probably the easiest thing I have done, but it's the only part I need help with.

Here is some ways I was thinking of accomplishing this.
Code:
For P = 4 To LColFC
    wksForecastSheet.Cells(LRowFC + 2, P).Value = WorksheetFunction.Sum(ActiveSheet.Cells(4, P).Name & ":" & ActiveSheet.Cells(I - 1, P).Name)
    wksForecastSheet.Cells(LRowFC + 3, P).Value = WorksheetFunction.Sum(Cells(I, P).Name & ":" & Cells(LColFC, P).Name)
Next
 
an example from the immediate window:
Code:
set r=sheet1.[a1:a16]
print application.WorksheetFunction.Sum(r)
 136

_________________
Bob Rashkin
 


Hi,

Use an actual range
Code:
WorksheetFunction.Sum(Range(Cells(4, P)), Range(Cells(I - 1, P))
where BOTH I and P are variables.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
What is I ?
Why using LColFC for a Row number ?
What do you want to do ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I" is a where one part of what I'm summing ends, I acquire it in the step before this with a while loop that finds the first instance of a string. I corrected the problem with the "LColFC", I have another variable that goes there, it was a typo.

I am trying to build a chart of Design and Engineering hours per month in a completely automated fashion. The program goes out into the work book finds all the project hours and then sorts them on the sheet after that I sum it all up and chart it.

Skips code worked with one adjustment, I only need the range class once and then put both cells inside the range separated by a comma and it appears to work.

Thanks for the responses.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top