RawlinsCross
Active Member
- Joined
- Sep 9, 2016
- Messages
- 437
So I have a table that I've filtered, and my understanding is that you have to deal with areas in such cases although I'm not terribly experienced in dealing with areas. What I want to do is that if the 5th column of a filtered list has only one unique value a certain subroutine will fire and if there are more than one unique value another subroutine will fire. It's not working out for me at the moment. Here's my attempt at the code. (The IsArrayAllocated is from CPearson's page)
VBA Code:
Dim wSht As Worksheet
Dim rRange As Range, rng As Range, rFinal As Range
Dim vArray As Variant
Set wSht = ThisWorkbook.Worksheets("Schedule")
Set rRange = wSht.Range("rngSchedule").Columns(5).SpecialCells(xlCellTypeVisible)
For Each rng In rRange.Areas
If rFinal Is Nothing Then
Set rFinal = rng
Else
Set rFinal = Union(rFinal, rng)
End If
Next rng
On Error Resume Next
vArray = Application.WorksheetFunction.Unique(rFinal) 'This will error if there are no duplicates and the code will follow the "ELSE" logic.
On Error GoTo 0
If IsArrayAllocated(vArray) Then
Set rRange = wSht.Rows(6)
rRange.ClearContents
Exit Sub
Else
Application.ScreenUpdating = False
Call PlacePCTOnCalcWS
Application.ScreenUpdating = True
End If
End Sub
Public Function IsArrayAllocated(arr As Variant) As Boolean
On Error Resume Next
IsArrayAllocated = IsArray(arr) And Not IsError(LBound(arr, 1)) And LBound(arr, 1) <= UBound(arr, 1)
End Function