Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Is there a way to count how many elements there are in an array?

But not by doing an for i = lbound(x()) to ubound(x()) and counter?

Thanks

Peter

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default Is there a way to count how many elements there are in an array?

On Aug 22, 12:01 am, Peter wrote:
But not by doing an for i = lbound(x()) to ubound(x()) and counter?

Thanks

Peter


Dim lngElements as Long
lngElements = WorksheetFunction.CountA(x)

will tell you the number of elements in the x array that have been
assigned a value.

Ken Johnson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Is there a way to count how many elements there are in an array?

Here is one way, assuming option base zero.

Sub arry()
Dim myArry As Variant
myArry = Array("This", "That", "Other")
MsgBox UBound(myArry) + 1
End Sub


"Peter" wrote:

But not by doing an for i = lbound(x()) to ubound(x()) and counter?

Thanks

Peter


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Is there a way to count how many elements there are in an array?

If the array (say arr1) is a one-dimensional array or a single column:

no. of elements = Ubound(arr1) - Lbound(arr1) + 1

If it's a 2 dimensional array:

no. of elements = (Ubound(arr1) - Lbound(arr1) + 1) * _
(Ubound(arr1,2) - Lbound(arr1,2) + 1

Alan Beban

Peter wrote:
But not by doing an for i = lbound(x()) to ubound(x()) and counter?

Thanks

Peter

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
array elements count madeleine[_2_] Excel Programming 6 December 8th 06 03:36 AM
Reference Elements w/in an Array M Moore Excel Discussion (Misc queries) 2 October 16th 06 03:33 PM
Shifting Array Elements Trip[_3_] Excel Programming 6 July 30th 05 07:30 PM
Refer to Elements in an array Derick[_2_] Excel Programming 3 February 9th 05 02:25 AM
Count elements in array Jason Morin[_3_] Excel Programming 7 January 31st 05 09:32 PM


All times are GMT +1. The time now is 02:26 PM.

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

About Us

"It's about Microsoft Excel"