Consulting

Results 1 to 5 of 5

Thread: Extracting Unique Values from a Column

  1. #1
    VBAX Regular
    Joined
    Nov 2006
    Posts
    7
    Location

    Extracting Unique Values from a Column

    Hi everybody

    A small piece of my following code seems plaqued with a number of errors.

     
     
     
    
    Private Sub CopyUniqueVals(SrcRng As Range, DestRng As Range)
    Range(SrcRng).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range(DestRng), Unique:=True
    End Sub
    Sub TestCopyUniqueVals()
    Dim SrcRange As Range, DestRange As Range
    Sheets("SubCon").Activate
    ' The following statement reports "Application-defined or object-defined error:
    Set SrcRange = Range(ActiveSheet.Range(ListOfVendors))
    ' The following statement reports "Method 'Range' of object '_Global' failed: ' The Range("C4:C614") is the same as ListOfVendors named range.
    Set SrcRange = Range(ActiveSheet.Range("C4:C614")) Set DestRange = Range(Sheets("Summary").Range("A15"))
    ' The following statement reports "ByRef argument type mismatch": ' Even if I use the same arguments ByVal, it reports "Argument type mismatch". Call CopyUniqueVals(SrcRange, DestRange)
    End Sub
    ' The following procedure lists the first vendor twice whereas; others are unique:
    Private Sub CopyUniqueVals2()
    Sheets("SubCon").Activate
    Range("C4:C614").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("Z4"), Unique:=True
    End Sub
    Thanks for any tip, in anticipation, for pointing out the mistakes and their remedy.
    Regards,

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    The namining convention for this line:
    [VBA]
    Set SrcRange = Range(ActiveSheet.Range(ListOfVendors))
    [/VBA]would be:
    [VBA]
    Set SrcRange = Activesheet.Range(ListOfVendors)
    [/VBA]so will your other ranges need changing to the correct format, as for you unique lists i don't know, can you post a sample workbook?
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    VBAX Regular
    Joined
    Nov 2006
    Posts
    7
    Location
    Thanks Simon for the tip. But, I am still having problem with the modified code, as below:

    [VBA]
    Private Sub CopyUniqueVals(Src As Range, Dest As Range)
    Sheets("SubCon").Activate

    ' The following statement works fine:
    ' Range("C4:C614").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range(Dest), Unique:=True

    ' But the following statement reports the error "Application-defined or object-defined error"
    ActiveSheet.Range(Src).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range(Dest), Unique:=True
    End Sub

    Sub TestCopyUniqueVals()
    Dim SrcRange As Range, DestRange As Range

    Sheets("SubCon").Activate

    Set SrcRange = ActiveSheet.Range("C4:C614")
    Set DestRange = Sheets("Summary").Range("A15")

    Call CopyUniqueVals(SrcRange, DestRange)
    End Sub
    [/VBA]
    Sorry for not understanding well. Further assistance is highly appreciated.

    Regards,

  4. #4
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Rather than post parts of your code post it in it's entirity, or better still post a sample workbook - what you may think is the problem may not be the cause!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  5. #5
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Cross posted today here where you have also had help, please read the link in my signature with regards to cross posting!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

Posting Permissions

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