Results 1 to 9 of 9

VBA modification to exclude empty cells, just need help implementing!!

Threaded View

  1. #1
    Registered User
    Join Date
    06-04-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    42

    Exclamation VBA modification to exclude empty cells, just need help implementing!!

    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
    Last edited by cronerd; 07-09-2013 at 12:07 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1