Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Determine if all items or elements are equal
Does anyone have a good way in VBA to determine if every element in an array
is the same/equal? Or if each item in a range is the same/equal? ie. are ('one','one','one') equal? Yes. Or are ('one','one','two') equal? No. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Determine if all items or elements are equal
Hi,
You could read through the array and check Sub Sonic() Dim ctrlArray As Variant ctrlArray = Application.Transpose(Range("a1:a10").Value) For x = 1 To UBound(ctrlArray) If ctrlArray(x) < ctrlArray(WorksheetFunction.Min(UBound(ctrlArray), x + 1)) Then MsgBox "Array elements aren't the same" GoTo getmeout End If Next getmeout: End Sub Mike "Shawn" wrote: Does anyone have a good way in VBA to determine if every element in an array is the same/equal? Or if each item in a range is the same/equal? ie. are ('one','one','one') equal? Yes. Or are ('one','one','two') equal? No. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Determine if all items or elements are equal
Shawn wrote:
Does anyone have a good way in VBA to determine if every element in an array is the same/equal? Or if each item in a range is the same/equal? ie. are ('one','one','one') equal? Yes. Or are ('one','one','two') equal? No. Hi. One idea to test if A1:A10 are the same. Sub Demo() Dim B As Boolean B = WorksheetFunction.CountIf([A1:A10], [A1]) = 10 End Sub = = = = = HTH :) Dana DeLouis |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Determine if all items or elements are equal
Another way IF your array is a String array (which your example seems to
indicate), this method will not work with a non-String array is like this... If Replace(Join(YourArray, ""), YourArray(LBound(YourArray))) = "" Then if you want case sensitive equality (one < One); or like this... If Replace(Join(YourArray, ""), YourArray(LBound( _ YourArray)), "", , , vbTextCompare) = "" Then if you want case insensitive equality (one = One) -- Rick (MVP - Excel) "Shawn" wrote in message ... Does anyone have a good way in VBA to determine if every element in an array is the same/equal? Or if each item in a range is the same/equal? ie. are ('one','one','one') equal? Yes. Or are ('one','one','two') equal? No. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Make sure all items in a Collection equal the same thing | Excel Programming | |||
Determine if item is in a range of items | Excel Programming | |||
How do I determine which numbers in a list equal a given sum? | Excel Discussion (Misc queries) | |||
Determine which cells from a specific range equal a certain sum | Excel Worksheet Functions | |||
lower and upper case equal on spreadsheet but not equal in VB | Excel Programming |