Hi there. I was wondering if there is a way to have the elements of an array counted. I have something like this:
How can I count the numbers of FALSE elements in the arrayTF() array? Your help is always very appreciated.Dim i, array(), arrayTF() 'The array() is already populated with random True or False elements For i= 1 To 20 If array(i, 1) = False Then arrayTF(i) = False Else arrayTF(i) = True End If Next j
Last edited by Rodas; 09-08-2009 at 02:39 PM.
There might be a quicker way, but you could loop through each element and use a counter.
Why are you moving the values from one array to another?
Sub x() Dim ab(1 To 100) As Boolean Dim i As Long Dim nFalse As Long For i = 1 To 100 ab(i) = Rnd > 0.5 Next i For i = 1 To 100 If Not ab(i) Then nFalse = nFalse + 1 Next i MsgBox nFalse End Sub
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
It was a quick idea that I had to resolve this (it was intented to re-populate the array for every column) but if there's a better idea, I won't hesitate in taking it. Thanks a lot.
Have you seen shg's code which does it all very neatly in one?
This is just what I was looking for, thanks a lot StephenR and shg. By the way (and just for the record), is there any function that does the same but without having to loop through the elements of the array?
Nevermind, I figured this out already, I just want to thank you guys for your help. Keep it up!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks