+ Reply to Thread
Results 1 to 2 of 2

How to copy repeated numbers

Hybrid View

  1. #1
    Registered User
    Join Date
    08-16-2007
    Posts
    7

    How to copy repeated numbers

    Does anybody know how to copy a repeated number from one cell to another.
    Example:
    I have a list of numbers (1,2,3,4,5,6,1,2,3,7,1,2) on cells A1 thru A12. As you can see numbers 1,2 are repeated on two ocassions and 3 is repeated once. How can I "automatically" populate cell B1 with the repeated number 1, cell B2 with the repeated number 2 and cell B3 with the number 3. Also, "automatically" populate cell C1 with the second repeated number 1 and cell C2 with the second repeated number 2.
    So, basically I just want to put in numbers in column A and "automatically" populate the other columns as the numbers repeat. Thank you.

    See attachment for example.
    Attached Images Attached Images

  2. #2
    Forum Contributor
    Join Date
    04-21-2007
    Location
    Lima, Peru
    MS-Off Ver
    2000, 2007, 2010
    Posts
    674

    Copying repeated numbers

    Hi

    Try the following code, which should work for any number of repeats.

    Sub Dup_copy()
    
    Dim a As Integer, b As Integer, c As Integer, lastrow As Integer
    
    Let lastrow = Range("a65536").End(xlUp).Row
    
    For a = 1 To lastrow
    
    Let b = Application.CountIf(Range(Cells(1, 1), Cells(lastrow, 1)), Cells(a, 1).Value)
    If b > 1 Then
    
    For c = 2 To b
    
    If Application.CountIf(Columns(c), Cells(a, 1).Value) = 0 Then
    Let Cells(1, c).Offset(Application.CountA(Columns(c)), 0) = Cells(a, 1).Value
    End If
    
    Next c
    
    End If
    
    Next a
    End Sub
    Regards

    Jeff

+ 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