+ Reply to Thread
Results 1 to 8 of 8

Matrix to Table

Hybrid View

  1. #1
    Registered User
    Join Date
    02-18-2017
    Location
    NL
    MS-Off Ver
    2010
    Posts
    2

    Matrix to Table

    Hi All,

    I'm looking for a script to create a datalist based upon the tab "Requirement" combined with the Bill Of Material of the tab BoM.

    Example is in the Total tab
    Attached Files Attached Files

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

    Re: Matrix to Table

    Try the attached.
    Sub test()
        Dim a, b, i As Long, ii As Long, iii As Long, n As Long, dic As Object
        Set dic = CreateObject("Scripting.Dictionary")
        dic.CompareMode = 1
        a = Sheets("bom").Cells(1).CurrentRegion.Value
        For i = 2 To UBound(a, 1)
            If Not dic.exists(a(i, 1)) Then
                Set dic(a(i, 1)) = CreateObject("System.Collections.ArrayList")
            End If
            dic(a(i, 1)).Add Array(a(i, 2), a(i, 3))
        Next
        a = Sheets("requirement").Cells(1).CurrentRegion.Value
        ReDim b(1 To 100000, 1 To 5): n = 1
        For i = 2 To UBound(a, 1)
            For ii = 2 To UBound(a, 2)
                If a(i, ii) <> "" Then
                    For iii = 0 To dic(a(1, ii)).Count - 1
                        n = n + 1: b(n, 1) = a(i, 1): b(n, 2) = a(i, ii): b(n, 3) = a(1, ii)
                        b(n, 4) = dic(a(1, ii))(iii)(0): b(n, 5) = dic(a(1, ii))(iii)(1)
                    Next
                End If
        Next ii, i
        With Sheets("total").Cells(1).Resize(n, 5)
            .CurrentRegion.ClearContents
            .Value = b
            .Rows(1).Value = Array("Customer", "Ordered", "Product", "Itemnr", "Quantity")
        End With
    End Sub
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    02-18-2017
    Location
    NL
    MS-Off Ver
    2010
    Posts
    2

    Re: Matrix to Table

    Works super Jindon!

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

    Re: Matrix to Table

    sir jindon what the mean this code
    b(n, 4) = dic(a(1, ii))(iii)(0): b(n, 5) = dic(a(1, ii))(iii)(1)

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

    Re: Matrix to Table

    Not interested in replying to a question from someone who ignores/makes no response.

    http://www.excelforum.com/excel-prog...ncatenate.html

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

    Re: Matrix to Table

    That line is to output the corresponding data stored in Dictionary
            dic(a(i, 1)).Add Array(a(i, 2), a(i, 3))
    to output array "b".

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

    Re: Matrix to Table

    Sir jindon i has use for loop without array
    Data in col a:d
    I want unique in col a dan sub unique in col b:d
    But still error sorri not in mark #
    Sub tes ()
    Dim d as object : set d = createobject("scripting.dictionary")
    For each r in columns(1).specialcells(2)
    If not d. Exists(r.value) then
    d.add r. Value, array(r.offset(,1),r. Offset(,2),r. Offset(,3))
    Else
    d.item(r.value) = d.item(r.value), array(r.offset(,1),r. Offset(,2),r. Offset(,3)).value
    End if
    Next
    For each v in d. Keys
    n=1:n=n+1
    range("a" & n) = v
    Range("b" & n) = d(v)
    Next
    End sub

    But i has not sukses











    Next

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

    Re: Matrix to Table

    Thankyou for attention mr. Jindon the problem solve..i hope your point will be up thank from triak..and bembeng

+ 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] Table Data to Matrix
    By uahmadov in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-14-2015, 02:42 PM
  2. Matrix to Table
    By kravi88 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-04-2014, 01:47 PM
  3. Replies: 1
    Last Post: 05-16-2014, 07:34 PM
  4. Matrix table
    By Onicle in forum Excel General
    Replies: 0
    Last Post: 04-16-2013, 08:12 AM
  5. Looking for a precise value in a table (matrix) ???
    By Sokol in forum Excel General
    Replies: 2
    Last Post: 01-17-2011, 07:23 AM
  6. [SOLVED] helps matrix table
    By mycarpark@gmail.com in forum Excel General
    Replies: 1
    Last Post: 06-15-2006, 07:25 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