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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sum of a range in a variable in excel 1

Status
Not open for further replies.

sunnytahir

Programmer
May 11, 2003
32
to anyone who knows best.
i want to sum a range in excel (in a variable) not in excel cell.
thanks.
 
Try something like this:
myVar = Application.WorksheetFunction.Sum(myRange)

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Dear phv,

This function does not work.

I have some values in Column A

I want to get the total of ( A1 to A5 ) in a variable.

Thanks in advance.
sunnytahir
 
Dear phv,

This function does not work.

I have some values in Column A

I want to get the total of ( A1 to A5 ) in a variable.

Thanks in advance.
sunnytahir

 
sunnytahir
What PHV is suggesting is replacing myRange with whatever your range is so in your case

myVar = Application.WorksheetFunction.Sum(Range("A1:A5"))

should do the trick

;-)

If a man says something and there are no women there to hear him, is he still wrong? [ponder]
The faqs ma'am, just the faqs. Get the best from these forums : faq222-2244
 
Hi sunnytahir,

sunnytahir said:
This function does not work

Well, this function does work. If what you have done doesn't work, we would be better able to help if we knew what you had done.

The Worksheet Sum Function can take a Range as an argument; my guess is you gave it a string, so try this ..

Code:
[blue][i]VariableName[/i] = Application.WorksheetFunction.Sum(ActiveSheet.Range("A1:A5"))[/blue]

.. and if you have trouble making this work, please post exactly what you have coded, and where.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top