+ Reply to Thread
Results 1 to 19 of 19

Extract unique value from range a1:a500 with one condition

Hybrid View

HaroonSid Extract unique value from... 02-14-2018, 02:12 PM
Fluff13 Re: Extract unique value from... 02-14-2018, 03:12 PM
HaroonSid Re: Extract unique value from... 02-16-2018, 03:39 PM
daboho Re: Extract unique value from... 02-14-2018, 03:34 PM
Fluff13 Re: Extract unique value from... 02-16-2018, 03:43 PM
Fluff13 Re: Extract unique value from... 02-16-2018, 03:57 PM
HaroonSid Re: Extract unique value from... 02-17-2018, 01:45 AM
HaroonSid Re: Extract unique value from... 02-17-2018, 01:57 AM
jindon Re: Extract unique value from... 02-17-2018, 02:07 AM
HaroonSid Re: Extract unique value from... 02-16-2018, 11:52 PM
leelnich Re: Extract unique value from... 02-17-2018, 12:24 AM
jindon Re: Extract unique value from... 02-17-2018, 12:46 AM
HaroonSid Re: Extract unique value from... 02-17-2018, 01:50 AM
jindon Re: Extract unique value from... 02-17-2018, 01:59 AM
HaroonSid Re: Extract unique value from... 02-17-2018, 02:02 AM
daboho Re: Extract unique value from... 02-17-2018, 01:50 AM
HaroonSid Re: Extract unique value from... 02-17-2018, 02:12 AM
jindon Re: Extract unique value from... 02-17-2018, 02:15 AM
HaroonSid Re: Extract unique value from... 02-17-2018, 02:44 AM
  1. #1
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Extract unique value from range a1:a500 with one condition

    Hi,
    I want to extract unique values from range a1:a500 in range b1 but only if range.Offset(0,102)= "4 OL BC"
    IF range.Offset(0,2)= not "4 OL BC then don't count that cell in range..

    For example
    A1=aam and c1=4 OL BC
    A2=aam and c2=4 OL BC
    A3=aat and c3=3 OL BC ( don't use this value because of not to be 4 OL BC)
    A4=kam and c1=4 OL BC

    Then Unique Value should be
    C1=aam
    C2=Kam
    Don't add a3.value because c3 is not 4 OL BC

    THNAKYOU
    Use Code-Tags for showing your code :
    Please mark your question Solved if there has been offered a solution that works fine for you
    If You like solutions provided by anyone, feel free to add reputation using STAR *

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,792

    Re: Extract unique value from range a1:a500 with one condition

    How about
    Sub getUnique()
    
       Dim Cl As Range
       
       With CreateObject("scripting.dictionary")
          For Each Cl In Range("A1:A500")
             If Cl.Offset(, 2) = "4 OL BC" And Not .exists(Cl.Value) Then .Add Cl.Value, Nothing
          Next Cl
          Range("B1").Resize(.Count).Value = Application.Transpose(.keys)
       End With
    End Sub

  3. #3
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: Extract unique value from range a1:a500 with one condition

    Quote Originally Posted by Fluff13 View Post
    How about
    Sub getUnique()
    
       Dim Cl As Range
       
       With CreateObject("scripting.dictionary")
          For Each Cl In Range("A1:A500")
             If Cl.Offset(, 2) = "4 OL BC" And Not .exists(Cl.Value) Then .Add Cl.Value, Nothing
          Next Cl
          Range("B1").Resize(.Count).Value = Application.Transpose(.keys)
       End With
    End Sub
    Thank you for reply
    its giving an error
    Runtime error 13
    Type mismatch

  4. #4
    Forum Expert
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,513

    Re: Extract unique value from range a1:a500 with one condition

    Sub test()
    Dim i as long,x
    With createobject("scripting.dictionary")
    With range("A1:C"&[A10000].end(3).row)
    .Autofilter 3,"4 OL BC"
     x =.specialcells(12).value
    .autofilter
    End with
    For i = 1 to ubound(x,1)
    .add x(i,1),nothing
    Next i
    columns(3).clearContents
    [C1].resize(.count,1).value =application.index(.keys,0,0)
    End with
    End sub
    Last edited by daboho; 02-14-2018 at 03:39 PM.

  5. #5
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,792

    Re: Extract unique value from range a1:a500 with one condition

    Which line is highlighted when you get the error?

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,792

    Re: Extract unique value from range a1:a500 with one condition

    If it's on this line
     Range("B1").Resize(.Count).Value = Application.Transpose(.keys)
    Then try
    Sub getUnique()
       
       Dim Cl As Range
       Dim Ky As Variant
       
       With CreateObject("scripting.dictionary")
          For Each Cl In Range("A1:A500")
             If Cl.Offset(, 2) = "4 OL BC" And Not .exists(Cl.Value) Then .Add Cl.Value, Nothing
          Next Cl
          For Each Ky In .keys
             Range("B" & Rows.Count).End(xlUp).Offset(1).Value = Ky
          Next Ky
       End With
    End Sub

  7. #7
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: Extract unique value from range a1:a500 with one condition

    Thank you
    this one is working perfectly

  8. #8
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: Extract unique value from range a1:a500 with one condition

    @Jindon
    i just made some changes in your code according to my need
    but i am not able to do work with this one
    Sub test()
        Dim a, i As Long
        Columns("Q").ClearContents
        a = [B2:B500].Resize(, -2).Value
        With CreateObject("Scripting.Dictionary")
            .CompareMode = 1
            For i = 1 To UBound(a, 1)
                If a(i, UBound(a, 2)) = "4 OL BC" Then .Item(a(i, 1)) = Empty
            Next
            If .Count Then
                [Q2].Resize(.Count).Value = Application.Transpose(.keys)
            Else
                MsgBox "No ""4 OL BC"" in Column " & Replace([b2].Offset(, 1).Address(0, 0), 1, "")
            End If
        End With
    End Sub
    I have to choose criteria from range a2:a500 and the extract unique values from range(b2:b500)

    i think i cant use negative value with resize property
    then what i do

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Extract unique value from range a1:a500 with one condition

    Quote Originally Posted by HaroonSid View Post
    I have to choose criteria from range a2:a500 and the extract unique values from range(b2:b500)

    i think i cant use negative value with resize property
    then what i do
    No, Resize property must have positive value.

    And I don't think I understand what you are trying to do.
    What is this question related to your original question?

  10. #10
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: Extract unique value from range a1:a500 with one condition

    For each cl in range(a1:a500)
    With This line error commig

  11. #11
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Extract unique value from range a1:a500 with one condition

    Quote Originally Posted by HaroonSid View Post
    For each cl in range(a1:a500)
    The interior address needs "".
    For each cl in range("a1:a500")
    Last edited by leelnich; 02-17-2018 at 12:31 AM.
    Clicking the Add Reputation star below helpful posts is a great way to show your appreciation.
    Please mark your threads as SOLVED upon conclusion (Thread Tools above Post # 1). - Lee

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Extract unique value from range a1:a500 with one condition

    Quote Originally Posted by HaroonSid View Post
    Hi,
    I want to extract unique values from range a1:a500 in range b1 but only if range.Offset(0,102)= "4 OL BC"
    Sub test()
        Dim a, i As Long
        Columns("b").ClearContents
        a = [a1:a500].Resize(, 103).Value
        With CreateObject("Scripting.Dictionary")
            .CompareMode = 1
            For i = 1 To UBound(a, 1)
                If a(i, UBound(a, 2)) = "4 OL BC" Then .Item(a(i, 1)) = Empty
            Next
            If .Count Then
                [b1].Resize(.Count).Value = Application.Transpose(.keys)
            Else
                MsgBox "No ""4 OL BC"" in Column " & Replace([a1].Offset(, 102).Address(0, 0), 1, "")
            End If
        End With
    End Sub

  13. #13
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: Extract unique value from range a1:a500 with one condition

    And thank you you2
    its more fast then others

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Extract unique value from range a1:a500 with one condition

    Quote Originally Posted by HaroonSid View Post
    And thank you you2
    its more fast then others
    Why don't you use faster one? (I don't believe it though)

  15. #15
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: Extract unique value from range a1:a500 with one condition

    @jindon
    that was for you
    And thank you you2
    its more fast then others
    you code is working fast very fast

  16. #16
    Forum Expert
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,513

    Re: Extract unique value from range a1:a500 with one condition

    Sub test()
    Dim r as range,rg as range,a(),i as long
    Set rg =[a1:a500]
    Redim a(1 to rg.rows.count,1 to 1)
    With createObject("scripting.dictionary")
     For each r in rg
      If r(1,103).value ="4 OL BC" then
         If not.exists(r.value) then
             i = i + 1
            .item(r.value) = i
            a(i,1) = r.value
        End if
      End if
     Next r
    End with
    [B1].Resize(i,1).value = a
    End sub

  17. #17
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: Extract unique value from range a1:a500 with one condition

    Your first code working with my need and working fast and perfectly

    but i need another version of your code

    For example
    B2=aam and A2=4 OL BC
    B3=aam and A3=4 OL BC
    B4=aat and A4=3 OL BC ( don't use this value because of not to be 4 OL BC)
    B5=kam and A5=4 OL BC

    Then Unique Value should be
    Q2=aam
    Q3=Kam
    Don't add B4.value because A4 is not 4 OL BC

  18. #18
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Extract unique value from range a1:a500 with one condition

    Then something like
    Sub test()
        Dim a, i As Long
        a = [a1:b500].Value
        With CreateObject("Scripting.Dictionary")
            .CompareMode = 1
            For i = 1 To UBound(a, 1)
                If a(i, 1) = "4 OL BC" Then .Item(a(i, 2)) = Empty
            Next
            If .Count Then
                [q2].Resize(.Count).Value = Application.Transpose(.keys)
            Else
                MsgBox "No ""4 OL BC"" in Column A"
            End If
        End With
    End Sub

  19. #19
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: Extract unique value from range a1:a500 with one condition

    Perfectly working

    thank you very much

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Count in the given range with 1 condition duplicate as unique
    By Sekars in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 01-30-2017, 03:19 AM
  2. [SOLVED] extract unique list from a range while other column is criteria
    By marinelkata in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-26-2016, 03:44 AM
  3. [SOLVED] Count Unique Values in a Range with Condition
    By vij8y in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 01-28-2015, 05:45 AM
  4. [SOLVED] Extract Unique values in range
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-08-2014, 06:39 AM
  5. Count unique value in a range of cell with a given condition
    By Kehjz in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-29-2014, 01:21 AM
  6. [SOLVED] Challange - Need to count # of unique names in a range WITH A CONDITION
    By vij8y in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-11-2013, 05:14 PM
  7. Replies: 3
    Last Post: 11-24-2011, 06:11 AM

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