Skip to main content
deleted 13 characters in body
Source Link
JvdV
  • 218
  • 2
  • 9

I think I found a solution that seemed the most elegant, and is fast:

Sub Test()

'Get a 1D-array from columns of interest
Dim arr As Variant: arr = Application.Index(Range("A1:AA1").Value, 1, Array(1, 2, 3, 6, 11, 24, 27))

'Check if all elements in array match the first element
With Application
    If .Count(.Match(arr, Array(arr(1)), 0)) = 7 Then
        Debug.Print "All equal to first cell"
    Else
        Debug.Print "Not all equal to first cell"
    End If
End With

End Sub

So effectively; Application.Count and Application.Match work together to replace the WorksheetFunction.CountIf quite seamlessly on any irregular non-continuous range. And therefor we prevent any iteration.

This would however not take into consideration exact matches (not case-sensitive). For that I would revert back to my initial attempt.

I think I found a solution that seemed the most elegant, and is fast:

Sub Test()

'Get a 1D-array from columns of interest
Dim arr As Variant: arr = Application.Index(Range("A1:AA1").Value, 1, Array(1, 2, 3, 6, 11, 24, 27))

'Check if all elements in array match the first element
With Application
    If .Count(.Match(arr, Array(arr(1)), 0)) = 7 Then
        Debug.Print "All equal to first cell"
    Else
        Debug.Print "Not all equal to first cell"
    End If
End With

End Sub

So effectively; Application.Count and Application.Match work together to replace the WorksheetFunction.CountIf quite seamlessly on any irregular non-continuous range. And therefor we prevent any iteration.

This would however not take into consideration exact matches (not case-sensitive). For that I would revert back to my initial attempt.

I think I found a solution that seemed the most elegant:

Sub Test()

'Get a 1D-array from columns of interest
Dim arr As Variant: arr = Application.Index(Range("A1:AA1").Value, 1, Array(1, 2, 3, 6, 11, 24, 27))

'Check if all elements in array match the first element
With Application
    If .Count(.Match(arr, Array(arr(1)), 0)) = 7 Then
        Debug.Print "All equal to first cell"
    Else
        Debug.Print "Not all equal to first cell"
    End If
End With

End Sub

So effectively; Application.Count and Application.Match work together to replace the WorksheetFunction.CountIf quite seamlessly on any irregular non-continuous range. And therefor we prevent any iteration.

This would however not take into consideration exact matches (not case-sensitive). For that I would revert back to my initial attempt.

added 215 characters in body
Source Link
JvdV
  • 218
  • 2
  • 9

I think I found a solution that seemed the most elegant, and is fast:

Sub Test()

'Get a 1D-array from columns of interest
Dim arr As Variant: arr = Application.Index(Range("A1:AA1").Value, 1, Array(1, 2, 3, 6, 11, 24, 27))

'Check if all elements in array match the first element
With Application
    If .Count(.Match(arr, Array(arr(1)), 0)) = 7 Then
        Debug.Print "All equal to first cell"
    Else
        Debug.Print "Not all equal to first cell"
    End If
End With

End Sub

So effectively; Application.Count and Application.Match work together to replace the WorksheetFunction.CountIf quite seamlessly on any irregular non-continuous range. And therefor we prevent any iteration.

This would however not take into consideration exact matches (not case-sensitive). For that I would revert back to my initial attempt.

I think I found a solution that seemed the most elegant, and is fast:

Sub Test()

'Get a 1D-array from columns of interest
Dim arr As Variant: arr = Application.Index(Range("A1:AA1").Value, 1, Array(1, 2, 3, 6, 11, 24, 27))

'Check if all elements in array match the first element
With Application
    If .Count(.Match(arr, Array(arr(1)), 0)) = 7 Then
        Debug.Print "All equal to first cell"
    Else
        Debug.Print "Not all equal to first cell"
    End If
End With

End Sub

This would however not take into consideration exact matches (not case-sensitive). For that I would revert back to my initial attempt.

I think I found a solution that seemed the most elegant, and is fast:

Sub Test()

'Get a 1D-array from columns of interest
Dim arr As Variant: arr = Application.Index(Range("A1:AA1").Value, 1, Array(1, 2, 3, 6, 11, 24, 27))

'Check if all elements in array match the first element
With Application
    If .Count(.Match(arr, Array(arr(1)), 0)) = 7 Then
        Debug.Print "All equal to first cell"
    Else
        Debug.Print "Not all equal to first cell"
    End If
End With

End Sub

So effectively; Application.Count and Application.Match work together to replace the WorksheetFunction.CountIf quite seamlessly on any irregular non-continuous range. And therefor we prevent any iteration.

This would however not take into consideration exact matches (not case-sensitive). For that I would revert back to my initial attempt.

Source Link
JvdV
  • 218
  • 2
  • 9

I think I found a solution that seemed the most elegant, and is fast:

Sub Test()

'Get a 1D-array from columns of interest
Dim arr As Variant: arr = Application.Index(Range("A1:AA1").Value, 1, Array(1, 2, 3, 6, 11, 24, 27))

'Check if all elements in array match the first element
With Application
    If .Count(.Match(arr, Array(arr(1)), 0)) = 7 Then
        Debug.Print "All equal to first cell"
    Else
        Debug.Print "Not all equal to first cell"
    End If
End With

End Sub

This would however not take into consideration exact matches (not case-sensitive). For that I would revert back to my initial attempt.