I have a VBA that pulls Unique values from a set of cells. My problem is that I do not want it to include empty cells as a unique cell, it currently treats the empty cells as unique and gives me back a "0". Below I have my VBA, also someone tried to help me with a modification that would ignore empty cells but I haven't been able to modify it correctly so if anyone could help me with this I would be deeply appreciative.
Note: I have highlighted in blue the area where I tried to input the modification code, if anyone understands VBA and knows how to incorporate the code in purple into the code in blue correctly it would solve my problem!
VBA:
Function Uniques(ByVal inputRange As Range)
Dim inputArray As Variant
Dim myColl As New Collection
Dim xVal As Variant
Dim outArray() As Variant
On Error Resume Next
With inputRange
inputArray = Application.Intersect(.Cells, .Parent.UsedRange).Value
End With
On Error GoTo 0
On Error Resume Next
For Each xVal In inputArray
myColl.Add Item:=xVal, Key:=(CStr(xVal) & TypeName(xVal))
Next xVal
myColl.Remove "String"
On Error GoTo 0
ReDim outArray(1 To Application.Max(myColl.Count, Application.Caller.Cells.Count))
For xVal = 1 To UBound(outArray)
outArray(xVal) = vbNullString
Next xVal
For xVal = 1 To Application.Min(myColl.Count, Application.Caller.Cells.Count)
outArray(xVal) = myColl(xVal)
Next xVal
If Application.Caller.Columns.Count = 1 Then
Uniques = Application.Transpose(outArray)
Else
Uniques = outArray
End If
End Function
Below is the Code given to me by other person, I was told to place this into the blue colored code above, but it didn't work :/
Each xVal In inputArray
If xVal = vbNullString And xVal <> 0 Then
myColl.Add Item:=CStr(xVal), key:=CStr(xVal)
End If
Next xVal
Bookmarks