Sub kTest()
    
    Dim x, ka, k(), i As Long, n As Long, c As Long, j As Long, p As Long
    
    With Worksheets("Query")
        ka = .Range("a1").CurrentRegion
    End With
    
    With CreateObject("scripting.dictionary")
        .comparemode = 1
        For c = 1 To UBound(ka, 2)
            If Not .exists(ka(1, c)) Then
                j = j + 1
                .Add ka(1, c), j
            End If
        Next
        ReDim k(1 To UBound(ka, 1) * UBound(ka, 2), 1 To j)
        For c = 1 To UBound(ka, 2) Step j
            For i = 2 To UBound(ka, 1)
                n = n + 1
                For p = 0 To j - 1
                    k(n, .Item(ka(1, c + p))) = ka(i, c + p)
                Next
            Next
        Next
        x = .keys
    End With
    
    If n Then
        With Worksheets("Sheet1").Range("a1")
            .Parent.UsedRange.ClearContents
            .Range("a1").Resize(, j) = x
            .Range("a2").Resize(n, j) = k
            .Parent.UsedRange.Columns.AutoFit
        End With
    End If
    
End Sub


Kris

-- 
FORUM RULES (986+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.

------------------------------------------------------------------------------------------------------
To post to this group, send email to excel-macros@googlegroups.com

Reply via email to