Results 1 to 12 of 12

Thread: [SOLVED]Finding unique values in column

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Location
    singapore
    Posts
    86

    Question [SOLVED]Finding unique values in column

    I have a column of data where I have to extract the unique values and display them in another column. I'm using this method to do it.
    PHP Code:
    Sub Find() 
    Worksheets("readtxt2").Activate 
    On Error Resume Next 
    If Range("A1").Value "" Then 
        
    '// handle the error here and End 
        MsgBox "Could NOT exercute" 
        End 
    End If 

                        '
    the range where it gets values n pastes it here 
    FindUniqueValues Range
    ("D2 : D3000"), Worksheets("readtxt2").Range("H1"
    On Error GoTo 
    End Sub 

    Sub FindUniqueValues
    (SourceRange As RangeTargetCell As Range
     
    SourceRange.AdvancedFilter Action:=xlFilterCopy
            CopyToRange
    :=TargetCellUnique:=True 
    However, when I run my program and get the unique values, I always get the first two rows of data of the same value(meaning range("A1") and ("A2") shows the same value) How to solve it? Pls help.Thankyou.
    Last edited by ITboy; Apr 13th, 2003 at 09:43 PM.

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    ??
    The code you showed does nothing to the Cells A1 nor A2!
    It looks thru the cells in D23000, find all unique values and prints them in Column H!!
    The only thing that is don e with anything in A is checking wether A1 is empty, if that'S true, nothing is done!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Location
    singapore
    Posts
    86
    Yes..thats exactly what is happening.... My ques is, when the data is extracted to column H, the first 2 rows("H1")n ("H2") has the same values... I want to solve that..Sorry, I forgot to quote that the above A1 and A2 wre just examples I was giving...

  4. #4
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    I tried to code, using BOGUS entries in Column D.The result was as desired!
    Maybe the values in your first two rows are not really the same, "B01" is not the same as "B01 "!!! (Check for Spaces!)
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Location
    singapore
    Posts
    86
    No..OPus.. Theyare exactly the same...There's no space whatsoever..I've checked it alreday thoroughly.. How can all the different files generated from the engine coz the same same mistake..? I wonder Pls help....mayb is there anyway to check and filter unique values again?...I don't know

  6. #6
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    Please post a .Xls containing a filled Column D that causes the failure, and with the code you use to do it!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Location
    singapore
    Posts
    86
    Here it is..Thank you.
    Attached Files Attached Files

  8. #8
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    The first value in the Range is never used, it is only displayed as a title.
    Look at the name of the Cell H1, its not H1 anymore it's called something like "destinationrange" (dependent on your languagesetting, mine is German, so I don'T have the correct one on hand)

    I'm out of here now!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Location
    singapore
    Posts
    86
    Opus...It worked..Jus changed a bit in my codes...
    PHP Code:
    Sub FindUniqueVessels(SourceRange As RangeTargetCell As Range)
     
        
    SourceRange.AdvancedFilter Action:=xlFilterCopy_
            CopyToRange
    :=TargetCellUnique:=True
        
         
    If Range("H1").Value Range("H2").Value Then
            Range
    ("H1").Select
            Selection
    .Delete Shift:=xlUp
           
          End 
    If
    End Sub 
    Don't get angry..I muself did not understand why the cell name is such..I noticed it too.

  10. #10
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    Why should I get angry,
    just because you did some coding on your own?
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Location
    singapore
    Posts
    86

    Cool

    No..what I meant was, it was my mistake for not being observant enough like u..U were the one to enlighten me bout the problem on Range("H1")..its only after that I was able to do.. Thanks alot.

  12. #12
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    Don't forget to reedit the topic and add "SOLVED" to it.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

Posting Permissions

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



Click Here to Expand Forum to Full Width