+ Reply to Thread
Results 1 to 3 of 3

give unique Values to set of data if rows are continues

Hybrid View

aravindhan_31 give unique Values to set of... 08-11-2009, 06:30 AM
MickG Re: give unique Values to set... 08-11-2009, 07:39 AM
aravindhan_31 Re: give unique Values to set... 08-21-2009, 06:34 AM
  1. #1
    Forum Contributor
    Join Date
    03-28-2008
    Location
    India, bangalore
    MS-Off Ver
    Excel 2003,2007
    Posts
    216

    give unique Values to set of data if rows are continues

    Hi
    I have some values in Sheet1 Colmn A like this.
    Col A
    A
    A
    A
    B
    B
    C
    A
    B
    A
    I need to give a unique set of values for the rows which are continues
    Col A Result
    A 1
    A 1
    A 1
    B 1
    B 1
    C 1
    A 2
    B 2
    A 3

    with the above example, first 3 values are continues so i give 1 for those, the next a appears after some other values so I assign 2 again A appears after some rows of data o I assign 3, similarly the same thing to be done for all the values in Column A
    Is this possible in formulas or a macro

    I have attached the sample file



    Appreciate your help
    Attached Files Attached Files

  2. #2
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: give unique Values to set of data if rows are continues

    Hi, Try this Your Data Must start in (Minium of) row 2, Column "A".
    Sub MG11Aug22
    Dim Rng As Range, Dn As Range, Q
    Set Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
    With CreateObject("scripting.dictionary")
    .CompareMode = vbTextCompare
    For Each Dn In Rng
        If Not .Exists(Dn.Value) Then
            .Add Dn.Value, Array(Dn.Value, 1)
            Dn.Next = 1
        Else
            Q = .Item(Dn.Value)
                If Dn.Offset(-1) = Dn.Value Then
                    Dn.Next = Q(1)
                Else: Q(1) = Q(1) + 1
                    Dn.Next = Q(1)
                    .Item(Dn.Value) = Q
                End If
        End If
    Next
    End With
    End Sub
    Regards Mick

  3. #3
    Forum Contributor
    Join Date
    03-28-2008
    Location
    India, bangalore
    MS-Off Ver
    Excel 2003,2007
    Posts
    216

    Re: give unique Values to set of data if rows are continues

    Hello Mick,

    I apologies for my delay in replying.. the code works fine for me.. thanks a lot..

    Arvind

+ Reply to Thread

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