ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Unlimited number of variables? (https://www.excelbanter.com/excel-programming/437792-unlimited-number-variables.html)

Faraz A. Qureshi

Unlimited number of variables?
 
Sometimes you never know how many variables you would be needing to gather a
data.

For example, =SUM(Variable-1, Variable-2, ...., Variable-n)

How to declare the same in this regard? Any sample shall be appreciated.

--
Thanx in advance,
Best Regards,

Faraz

Jacob Skaria

Unlimited number of variables?
 
Use an array. In the below example variable arrTemp is redimensioned at
runtime to store values 1 to 1000..at position 1 to 1000...

http://msdn.microsoft.com/en-us/libr...s2(VS.71).aspx

Dim arrTemp As Variant
ReDim arrTemp(0)

For intCount = 1 To 1000
ReDim Preserve arrTemp(intCount)
arrTemp(intCount) = intCount
Next

--
Jacob


"Faraz A. Qureshi" wrote:

Sometimes you never know how many variables you would be needing to gather a
data.

For example, =SUM(Variable-1, Variable-2, ...., Variable-n)

How to declare the same in this regard? Any sample shall be appreciated.

--
Thanx in advance,
Best Regards,

Faraz


Faraz A. Qureshi

Unlimited number of variables?
 
Sorry Jacob but the picture's still unclear. Buddy, can you please simply
design a simple sum type of a function like:

=XSUM(Variable-1, Variable-2, ...., Variable-n)

With a ReDim statement used?

Thanx again,
Best Regards,

Faraz


"Jacob Skaria" wrote:

Use an array. In the below example variable arrTemp is redimensioned at
runtime to store values 1 to 1000..at position 1 to 1000...

http://msdn.microsoft.com/en-us/libr...s2(VS.71).aspx

Dim arrTemp As Variant
ReDim arrTemp(0)

For intCount = 1 To 1000
ReDim Preserve arrTemp(intCount)
arrTemp(intCount) = intCount
Next

--
Jacob


"Faraz A. Qureshi" wrote:

Sometimes you never know how many variables you would be needing to gather a
data.

For example, =SUM(Variable-1, Variable-2, ...., Variable-n)

How to declare the same in this regard? Any sample shall be appreciated.

--
Thanx in advance,
Best Regards,

Faraz


Dana DeLouis[_3_]

Unlimited number of variables?
 
Sometimes you never know how many variables you would be needing...

Hi. You may be looking for the ParamArray option.
Example:

Function MySum(ParamArray v() As Variant)
MySum = WorksheetFunction.Sum(v)
End Function

Sub TestIt()
Debug.Print MySum(1, 2, 3)
Debug.Print MySum(1, 2, 3, 4, 5, 6)
End Sub

= = = = = = = = = =
HTH :)
Dana DeLouis



On 12/26/2009 12:56 AM, Faraz A. Qureshi wrote:
Sorry Jacob but the picture's still unclear. Buddy, can you please simply
design a simple sum type of a function like:

=XSUM(Variable-1, Variable-2, ...., Variable-n)

With a ReDim statement used?

Thanx again,
Best Regards,

Faraz


"Jacob Skaria" wrote:

Use an array. In the below example variable arrTemp is redimensioned at
runtime to store values 1 to 1000..at position 1 to 1000...

http://msdn.microsoft.com/en-us/libr...s2(VS.71).aspx

Dim arrTemp As Variant
ReDim arrTemp(0)

For intCount = 1 To 1000
ReDim Preserve arrTemp(intCount)
arrTemp(intCount) = intCount
Next

--
Jacob


"Faraz A. Qureshi" wrote:

Sometimes you never know how many variables you would be needing to gather a
data.

For example, =SUM(Variable-1, Variable-2, ...., Variable-n)

How to declare the same in this regard? Any sample shall be appreciated.

--
Thanx in advance,
Best Regards,

Faraz




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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com