Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 190
Default declare multiple variables

hi,

is there any way i can declare multiple variables at the same time without
creating tons of different functions. for example, lets say i have:

Function zum() As Variant
Application.Volatile
zum = 0
For Each w In Worksheets
zum = zum + w.Range("C2").Value
Next
End Function

i want to be able to modify it to something like:

Function zum() As Variant
Application.Volatile
zum = 0
For Each w In Worksheets
zum = zum + w.Range("C2").Value
zum2 = zum2 + w.Range("D2").Value
zum3 = zum3 + w.Range("F2").Value
Next
End Function


how should I modify it?

thanks in advance,
geebee


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default declare multiple variables

It looks like you are doing a UDF which by default can only return one value.
How about something more like this...

Function zum(byval Target as range) As double
dim w as worksheet

Application.Volatile
zum = 0
For Each w In Worksheets
zum = zum + w.Range(Target.Address).Value
Next w
End Function

Use it like
=Zum(C2)
or
=Zum(D2)

--
HTH...

Jim Thomlinson


"geebee" wrote:

hi,

is there any way i can declare multiple variables at the same time without
creating tons of different functions. for example, lets say i have:

Function zum() As Variant
Application.Volatile
zum = 0
For Each w In Worksheets
zum = zum + w.Range("C2").Value
Next
End Function

i want to be able to modify it to something like:

Function zum() As Variant
Application.Volatile
zum = 0
For Each w In Worksheets
zum = zum + w.Range("C2").Value
zum2 = zum2 + w.Range("D2").Value
zum3 = zum3 + w.Range("F2").Value
Next
End Function


how should I modify it?

thanks in advance,
geebee


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default declare multiple variables

Hi,

replace the line:
zum = zum + w.Range(Target.Address).Value

with this line:
zum = zum + worksheetfunction.sum(w.Range(Target.Address)

It should work

Much fun, Heimo


"geebee" (noSPAMs) schrieb im Newsbeitrag
...
hi,

this works good. but now i would like to know how i can add hem. lts say
for example that cell C1 has a formula of =zum(E12) in it. and cell C2 has
a
formula of =zum(E13) in it. and so forth. i would like to know how i can
add these zums up in cell C5.i tried to use =sum(C1:C4) but its not
working.

thanks in advance,
geebee


"Jim Thomlinson" wrote:

It looks like you are doing a UDF which by default can only return one
value.
How about something more like this...

Function zum(byval Target as range) As double
dim w as worksheet

Application.Volatile
zum = 0
For Each w In Worksheets
zum = zum + w.Range(Target.Address).Value
Next w
End Function

Use it like
=Zum(C2)
or
=Zum(D2)

--
HTH...

Jim Thomlinson


"geebee" wrote:

hi,

is there any way i can declare multiple variables at the same time
without
creating tons of different functions. for example, lets say i have:

Function zum() As Variant
Application.Volatile
zum = 0
For Each w In Worksheets
zum = zum + w.Range("C2").Value
Next
End Function

i want to be able to modify it to something like:

Function zum() As Variant
Application.Volatile
zum = 0
For Each w In Worksheets
zum = zum + w.Range("C2").Value
zum2 = zum2 + w.Range("D2").Value
zum3 = zum3 + w.Range("F2").Value
Next
End Function


how should I modify it?

thanks in advance,
geebee




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Declare variables to a code? Pas Excel Discussion (Misc queries) 6 April 10th 10 01:14 PM
Declare Variables in Array Mike H. Excel Discussion (Misc queries) 2 March 11th 09 12:33 PM
Declare and Set Public variables jlclyde Excel Discussion (Misc queries) 2 January 28th 09 02:16 PM
How to efficiently declare variables Jeff Excel Discussion (Misc queries) 2 June 29th 06 01:56 PM
Best place to declare variables Taras Excel Programming 7 November 27th 03 04:34 PM


All times are GMT +1. The time now is 10:27 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"