Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Size of array

I would like to scan an array which my function does not know the size.
Are there any statement to return size of array like Sizeof or Length then I
can scan the whole array.

any infoomation is great appreciated,


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Size of array

You can use a For Each loop on an array. Or, if you want to go by
index, use code like

Dim Ndx As Long
For Ndx = LBound(Arr) To UBound(Arr)
' do something with Arr(Ndx)
Next Ndx


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Souris" wrote in message
...
I would like to scan an array which my function does not know
the size.
Are there any statement to return size of array like Sizeof or
Length then I
can scan the whole array.

any infoomation is great appreciated,




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Size of array

Try using UBOUND and LBOUND to give you the upper and lower bounds of the
array.

Regards

Trevor


"Souris" wrote in message
...
I would like to scan an array which my function does not know the size.
Are there any statement to return size of array like Sizeof or Length then
I
can scan the whole array.

any infoomation is great appreciated,




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Size of array

The type of parameter is Variant.
How can I redim the type to Array before scan it without knowing the size?
Thanks again,

"Chip Pearson" wrote:

You can use a For Each loop on an array. Or, if you want to go by
index, use code like

Dim Ndx As Long
For Ndx = LBound(Arr) To UBound(Arr)
' do something with Arr(Ndx)
Next Ndx


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Souris" wrote in message
...
I would like to scan an array which my function does not know
the size.
Are there any statement to return size of array like Sizeof or
Length then I
can scan the whole array.

any infoomation is great appreciated,





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Size of array

Dim v as Variant
redim v(1 to 10)

or if you are picking up a range from the worksheet

Dim v as Variant
v = Range("A1:F10").Value
for i = lbound(v,1) to ubound(v,1)
for j = lbound(v,2) to ubound(v,2)
debug.print "v(" & i & "," & j & ")=" & v(i,j)
next j ' column
next i ' row

Array isn't a type like variant, long or double. It is a storage structure.

Other than that, for me, you would need to ask a clearer question.
--
Regards,
Tom Ogilvy




"Souris" wrote in message
...
The type of parameter is Variant.
How can I redim the type to Array before scan it without knowing the size?
Thanks again,

"Chip Pearson" wrote:

You can use a For Each loop on an array. Or, if you want to go by
index, use code like

Dim Ndx As Long
For Ndx = LBound(Arr) To UBound(Arr)
' do something with Arr(Ndx)
Next Ndx


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Souris" wrote in message
...
I would like to scan an array which my function does not know
the size.
Are there any statement to return size of array like Sizeof or
Length then I
can scan the whole array.

any infoomation is great appreciated,









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Size of array

My original problem was to get unknown max numbers from my range for example 3.
Because worksheet functions do not support this.
I need to write a function to do this.
VBA does not let me pass array type to the function.
I have to pass varaint type to the function.

My formula shows "#VALUE!" on the spreadsheet, if the range has some spaces
and the number passed less than 3 numbers.

I tried to get rid of the "#VALUE!" on the cells.

Here is my function code.

Public Function GET_LARGEST_NUMBER_SUM(ARR As Variant, k As Long) As Long

Dim i As Integer
ReDim ARR(1 To 10)

For i = 1 To UBound(ARR)
If IsEmpty(ARR(i)) Then ARR(i) = 0
Next i


For i = 1 To k
GET_LARGEST_NUMBER_SUM = GET_LARGEST_NUMBER_SUM + _
Application.WorksheetFunction.Large(ARR, i)
Next i

End Function

=IF(VLOOKUP("HOME WORK",NPARAMETER,4,0)=-1,(SUM(G12:P12)/VLOOKUP( "HOME
WORK",NPARAMETER,3,FALSE)),IF(VLOOKUP("HOME
WORK",NPARAMETER,4,0)=0,IF(COUNT(G12:P12) 0,
AVERAGE(G12:P12),0),GET_LARGEST_NUMBER_SUM(G12:P12 ,VLOOKUP("HOME
WORK",NPARAMETER,4,0))/VLOOKUP("HOME WORK",NPARAMETER,4,0)))

VLOOKUP("HOME WORK",NPARAMETER,4,0) = 3

Thanks millions,

"Tom Ogilvy" wrote:

Dim v as Variant
redim v(1 to 10)

or if you are picking up a range from the worksheet

Dim v as Variant
v = Range("A1:F10").Value
for i = lbound(v,1) to ubound(v,1)
for j = lbound(v,2) to ubound(v,2)
debug.print "v(" & i & "," & j & ")=" & v(i,j)
next j ' column
next i ' row

Array isn't a type like variant, long or double. It is a storage structure.

Other than that, for me, you would need to ask a clearer question.
--
Regards,
Tom Ogilvy




"Souris" wrote in message
...
The type of parameter is Variant.
How can I redim the type to Array before scan it without knowing the size?
Thanks again,

"Chip Pearson" wrote:

You can use a For Each loop on an array. Or, if you want to go by
index, use code like

Dim Ndx As Long
For Ndx = LBound(Arr) To UBound(Arr)
' do something with Arr(Ndx)
Next Ndx


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Souris" wrote in message
...
I would like to scan an array which my function does not know
the size.
Are there any statement to return size of array like Sizeof or
Length then I
can scan the whole array.

any infoomation is great appreciated,








  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Size of array

Perhaps:

Public Function GET_LARGEST_NUMBER_SUM(ARR As Range, k As Variant) As
Variant
Dim v As Variant
Dim i As Integer
v = Application.Transpose(Application.Transpose(ARR))
For i = 1 To UBound(v)
If IsEmpty(v(i)) Then v(i) = 0
Next i


For i = 1 To k
GET_LARGEST_NUMBER_SUM = GET_LARGEST_NUMBER_SUM + _
Application.WorksheetFunction.Large(v, i)
Next i

End Function

--
Regards,
Tom Ogilvy

"Souris" wrote in message
...
My original problem was to get unknown max numbers from my range for

example 3.
Because worksheet functions do not support this.
I need to write a function to do this.
VBA does not let me pass array type to the function.
I have to pass varaint type to the function.

My formula shows "#VALUE!" on the spreadsheet, if the range has some

spaces
and the number passed less than 3 numbers.

I tried to get rid of the "#VALUE!" on the cells.

Here is my function code.

Public Function GET_LARGEST_NUMBER_SUM(ARR As Variant, k As Long) As Long

Dim i As Integer
ReDim ARR(1 To 10)

For i = 1 To UBound(ARR)
If IsEmpty(ARR(i)) Then ARR(i) = 0
Next i


For i = 1 To k
GET_LARGEST_NUMBER_SUM = GET_LARGEST_NUMBER_SUM + _
Application.WorksheetFunction.Large(ARR, i)
Next i

End Function

=IF(VLOOKUP("HOME WORK",NPARAMETER,4,0)=-1,(SUM(G12:P12)/VLOOKUP( "HOME
WORK",NPARAMETER,3,FALSE)),IF(VLOOKUP("HOME
WORK",NPARAMETER,4,0)=0,IF(COUNT(G12:P12) 0,
AVERAGE(G12:P12),0),GET_LARGEST_NUMBER_SUM(G12:P12 ,VLOOKUP("HOME
WORK",NPARAMETER,4,0))/VLOOKUP("HOME WORK",NPARAMETER,4,0)))

VLOOKUP("HOME WORK",NPARAMETER,4,0) = 3

Thanks millions,

"Tom Ogilvy" wrote:

Dim v as Variant
redim v(1 to 10)

or if you are picking up a range from the worksheet

Dim v as Variant
v = Range("A1:F10").Value
for i = lbound(v,1) to ubound(v,1)
for j = lbound(v,2) to ubound(v,2)
debug.print "v(" & i & "," & j & ")=" & v(i,j)
next j ' column
next i ' row

Array isn't a type like variant, long or double. It is a storage

structure.

Other than that, for me, you would need to ask a clearer question.
--
Regards,
Tom Ogilvy




"Souris" wrote in message
...
The type of parameter is Variant.
How can I redim the type to Array before scan it without knowing the

size?
Thanks again,

"Chip Pearson" wrote:

You can use a For Each loop on an array. Or, if you want to go by
index, use code like

Dim Ndx As Long
For Ndx = LBound(Arr) To UBound(Arr)
' do something with Arr(Ndx)
Next Ndx


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Souris" wrote in message
...
I would like to scan an array which my function does not know
the size.
Are there any statement to return size of array like Sizeof or
Length then I
can scan the whole array.

any infoomation is great appreciated,










  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Size of array

Thanks millions,

It works,

Souris,


"Tom Ogilvy" wrote in message
...
Perhaps:

Public Function GET_LARGEST_NUMBER_SUM(ARR As Range, k As Variant) As
Variant
Dim v As Variant
Dim i As Integer
v = Application.Transpose(Application.Transpose(ARR))
For i = 1 To UBound(v)
If IsEmpty(v(i)) Then v(i) = 0
Next i


For i = 1 To k
GET_LARGEST_NUMBER_SUM = GET_LARGEST_NUMBER_SUM + _
Application.WorksheetFunction.Large(v, i)
Next i

End Function

--
Regards,
Tom Ogilvy

"Souris" wrote in message
...
My original problem was to get unknown max numbers from my range for

example 3.
Because worksheet functions do not support this.
I need to write a function to do this.
VBA does not let me pass array type to the function.
I have to pass varaint type to the function.

My formula shows "#VALUE!" on the spreadsheet, if the range has some

spaces
and the number passed less than 3 numbers.

I tried to get rid of the "#VALUE!" on the cells.

Here is my function code.

Public Function GET_LARGEST_NUMBER_SUM(ARR As Variant, k As Long) As Long

Dim i As Integer
ReDim ARR(1 To 10)

For i = 1 To UBound(ARR)
If IsEmpty(ARR(i)) Then ARR(i) = 0
Next i


For i = 1 To k
GET_LARGEST_NUMBER_SUM = GET_LARGEST_NUMBER_SUM + _
Application.WorksheetFunction.Large(ARR, i)
Next i

End Function

=IF(VLOOKUP("HOME WORK",NPARAMETER,4,0)=-1,(SUM(G12:P12)/VLOOKUP( "HOME
WORK",NPARAMETER,3,FALSE)),IF(VLOOKUP("HOME
WORK",NPARAMETER,4,0)=0,IF(COUNT(G12:P12) 0,
AVERAGE(G12:P12),0),GET_LARGEST_NUMBER_SUM(G12:P12 ,VLOOKUP("HOME
WORK",NPARAMETER,4,0))/VLOOKUP("HOME WORK",NPARAMETER,4,0)))

VLOOKUP("HOME WORK",NPARAMETER,4,0) = 3

Thanks millions,

"Tom Ogilvy" wrote:

Dim v as Variant
redim v(1 to 10)

or if you are picking up a range from the worksheet

Dim v as Variant
v = Range("A1:F10").Value
for i = lbound(v,1) to ubound(v,1)
for j = lbound(v,2) to ubound(v,2)
debug.print "v(" & i & "," & j & ")=" & v(i,j)
next j ' column
next i ' row

Array isn't a type like variant, long or double. It is a storage

structure.

Other than that, for me, you would need to ask a clearer question.
--
Regards,
Tom Ogilvy




"Souris" wrote in message
...
The type of parameter is Variant.
How can I redim the type to Array before scan it without knowing the

size?
Thanks again,

"Chip Pearson" wrote:

You can use a For Each loop on an array. Or, if you want to go by
index, use code like

Dim Ndx As Long
For Ndx = LBound(Arr) To UBound(Arr)
' do something with Arr(Ndx)
Next Ndx


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Souris" wrote in message
...
I would like to scan an array which my function does not know
the size.
Are there any statement to return size of array like Sizeof or
Length then I
can scan the whole array.

any infoomation is great appreciated,












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
Resetting the array size to Zero. Hari Prasadh Excel Programming 1 January 21st 05 03:39 PM
can i reduce an array to size of 0 Steven Deng Excel Programming 2 November 11th 04 07:19 PM
How to find out the size of a variable-size array ? Adrian[_7_] Excel Programming 1 July 6th 04 09:12 AM
Array Size Srinath Excel Programming 4 August 15th 03 07:58 PM
Array size ten Excel Programming 6 August 12th 03 09:16 AM


All times are GMT +1. The time now is 08:29 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"