Macro Chart Creating

levanoj

Active Member
Joined
Oct 25, 2007
Messages
311
So I have data that appears as follows:
MODLBUTN(Test2).xlsx
ABCD
1LACTRIDGroup
224564Mort
324574Mort
424584Mort
524595Muni
624605Muni
724615Muni
824566EM
924576EM
1024586EM
1124597Deriv
1224607Deriv
1324618Mort
1424688Mort
1524698Mort
1624708Mort
Sheet1


and I'd like a macro to pull the unique "LAC" values (column A) and the unique "TRID" values (Row 1) and convert that data into a chart that appears as follows:
MODLBUTN(Test2).xlsx
ABCDEF
1TRID45678
2Lac
32456MortEM
42457MortEM
52458MortEM
62459MuniDeriv
72460MuniDeriv
82461MuniMort
92468Mort
102469Mort
112470Mort
Sheet2


where the corresponding "Group" value in Sheet1 is inserted in the cell where the LAC & TRID intersect.
 
Last edited:

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try this :-
Results sheet(2)
Code:
[COLOR=navy]Sub[/COLOR] MG28Jun23
[COLOR=navy]Dim[/COLOR] Rng      [COLOR=navy]As[/COLOR] Range
[COLOR=navy]Dim[/COLOR] Dn       [COLOR=navy]As[/COLOR] Range
[COLOR=navy]Dim[/COLOR] n        [COLOR=navy]As[/COLOR] [COLOR=navy]Integer[/COLOR]
[COLOR=navy]Dim[/COLOR] Ray1
[COLOR=navy]Dim[/COLOR] Ray2
[COLOR=navy]Dim[/COLOR] Q
[COLOR=navy]Dim[/COLOR] oMax     [COLOR=navy]As[/COLOR] [COLOR=navy]Integer[/COLOR]
[COLOR=navy]Dim[/COLOR] K
[COLOR=navy]Dim[/COLOR] Rw       [COLOR=navy]As[/COLOR] [COLOR=navy]Long[/COLOR]
[COLOR=navy]Dim[/COLOR] Lst      [COLOR=navy]As[/COLOR] [COLOR=navy]Long[/COLOR]
[COLOR=navy]Set[/COLOR] Rng = Range(Range("A2"), Range("A" & rows.count).End(xlUp))
 Ray1 = GetRw(Rng.Offset(, 1))
   ReDim Ray2(1 To Rng.count, 1 To UBound(Ray1))
     [COLOR=navy]With[/COLOR] CreateObject("scripting.dictionary")
      .CompareMode = vbTextCompare
        [COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Dn [COLOR=navy]In[/COLOR] Rng
            [COLOR=navy]If[/COLOR] Not .Exists(Dn.value) [COLOR=navy]Then[/COLOR]
                n = n + 1
                Ray2(1, 1) = Dn.Offset(, 2)
                Ray2(1, 2) = Dn.Offset(, 1)
                .Add Dn.value, Array(Ray2, 1)
            [COLOR=navy]Else[/COLOR]
                Q = .Item(Dn.value)
                Q(1) = Q(1) + 1
                Q(0)(Q(1), 1) = Dn.Offset(, 2)
                Q(0)(Q(1), 2) = Dn.Offset(, 1)
                .Item(Dn.value) = Q
                oMax = Application.max(Q(1), oMax)
            [COLOR=navy]End[/COLOR] If
[COLOR=navy]Next[/COLOR]
Rw = 2
   Lst = .count
      ReDim nRay(1 To .count + 2, 1 To UBound(Ray1) + 2)
       nRay(1, 1) = "Trid": nRay(2, 1) = "Lac"
[COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] K [COLOR=navy]In[/COLOR] .keys
    Rw = Rw + 1
    [COLOR=navy]For[/COLOR] n = 1 To .Item(K)(1)
        nRay(Rw, 1) = K
        nRay(Rw, .Item(K)(0)(n, 2) - 2) = .Item(K)(0)(n, 1)
    [COLOR=navy]Next[/COLOR] n
[COLOR=navy]Next[/COLOR] K
[COLOR=navy]End[/COLOR] With
[COLOR=navy]With[/COLOR] Sheets("sheet2")
    .Range("A1").Resize(Lst + 2, UBound(Ray1) + 2) = nRay
    .Range("B1").Resize(, UBound(Ray1) + 1) = Ray1
[COLOR=navy]End[/COLOR] With
MsgBox "Run!!"
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Function GetRw(fRng [COLOR=navy]As[/COLOR] Range) [COLOR=navy]As[/COLOR] Variant
[COLOR=navy]Dim[/COLOR] Dn [COLOR=navy]As[/COLOR] Range
    [COLOR=navy]With[/COLOR] CreateObject("scripting.dictionary")
        .CompareMode = vbTextCompare
        [COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Dn [COLOR=navy]In[/COLOR] fRng
            .Item(Dn.value) = Dn.value
        [COLOR=navy]Next[/COLOR]
    GetRw = .keys
[COLOR=navy]End[/COLOR] With
[COLOR=navy]End[/COLOR] Function
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,254
Members
452,900
Latest member
LisaGo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top