Results 1 to 8 of 8

Transpose data from one column based on criteria of a different column with VBA Arrays

Threaded View

Anasurimbor Transpose data from one... 09-03-2018, 07:04 AM
jindon Re: Transpose data from one... 09-03-2018, 07:41 AM
Anasurimbor Re: Transpose data from one... 09-03-2018, 07:53 AM
WideBoyDixon Re: Transpose data from one... 09-03-2018, 08:00 AM
Anasurimbor Re: Transpose data from one... 09-03-2018, 08:25 AM
WideBoyDixon Re: Transpose data from one... 09-03-2018, 08:36 AM
Anasurimbor Re: Transpose data from one... 09-03-2018, 09:01 AM
jindon Re: Transpose data from one... 09-03-2018, 08:48 AM
  1. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Transpose data from one column based on criteria of a different column with VBA Arrays

    Try change to
    Sub test()
        Dim a, e, s, i As Long, txt As String, maxCol As Long, n As Long, t As Long
        a = Sheets("contracts").Cells(1).CurrentRegion.Value
        With CreateObject("Scripting.Dictionary")
            For i = 1 To UBound(a, 1)
                If Not .exists(a(i, 1)) Then
                    Set .Item(a(i, 1)) = CreateObject("Scripting.Dictionary")
                    .Item(a(i, 1)).CompareMode = 1
                End If
                txt = Join(Array(a(i, 2), a(i, 3)), Chr(2))
                .Item(a(i, 1))(txt) = a(i, 2)
                maxCol = Application.Max(maxCol, .Item(a(i, 1)).Count + 1)
            Next
            ReDim a(1 To .Count, 1 To maxCol)
            For Each e In .keys
                n = n + 1: a(n, 1) = e: t = 1
                For Each s In .Item(e)
                    t = t + 1: a(n, t) = .Item(e)(s)
                Next
            Next
        End With
        With Sheets.Add.Cells(1).Resize(n, maxCol)
            .Value = a
            If maxCol > 2 Then
                .Cells(1, 2).Value = .Cells(1, 2).Value & 1
                .Cells(1, 2).AutoFill .Cells(1, 2).Resize(, maxCol - 2)
            End If
            .Columns.AutoFit
        End With
    End Sub
    Last edited by jindon; 09-03-2018 at 10:48 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Rewrite VBA script from Column based arrays to Rows based arrays
    By wtell319 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-11-2018, 09:24 AM
  2. Transfer data based on value in Column using arrays
    By salmasaied in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 10-07-2016, 02:15 AM
  3. multiple look up arrays to sum column based on various criteria
    By deanusa in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-14-2016, 04:11 AM
  4. Replies: 11
    Last Post: 02-16-2016, 11:06 PM
  5. [SOLVED] Copy data from column to other sheets, based upon vlookup/criteria on column a
    By jedemeyer1 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 03-27-2013, 04:01 AM
  6. Excel Transpose Column to Rows Based on Criteria
    By lilianphoebs in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-22-2011, 02:57 PM
  7. Excel Transpose Column to Rows Based on Criteria
    By lilianphoebs in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-14-2011, 10:49 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