Stumped Again

anwaee2

Board Regular
Joined
Sep 13, 2012
Messages
151
Office Version
  1. 2011
Platform
  1. MacOS
I can do a join/transpose with one column but nothing I have tried will do a join/transpose with the condition being in two columns. Below is a sample of what I am trying to do. Thanks for any help you may give.

ABCD
FruitNumberSequenceShown
Apples#311
Oranges#122
Pears#131
Lemons#242
Oranges#1 52
Lemons#262
Apples #1 73
Plums#1 81
Apples#193
Pears#2101
Apples#1113
Oranges#2121
FROM ABOVE TO BELOW
ABCD
FruitNumberSequenceShown
Apples#17, 9, 113
Apples#311
Lemons#24, 62
Oranges#12, 52
Oranges#2121
Pears#132
Pears#2101
Plums#181

<colgroup><col width="65" span="4" style="width: 65pt;"></colgroup><tbody>
</tbody>

<colgroup><col width="65" span="4" style="width: 65pt;"></colgroup><tbody>
</tbody>
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Try this:-
NB:- This code will alter your data
Code:
[COLOR="Navy"]Sub[/COLOR] MG08Jan15
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Txt [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String,[/COLOR] nRng [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
Txt = Dn.Value & Dn.Offset(, 1).Value
    [COLOR="Navy"]If[/COLOR] Not .Exists(Txt) [COLOR="Navy"]Then[/COLOR]
        .Add Txt, Dn.Offset(, 2)
    [COLOR="Navy"]Else[/COLOR]
        [COLOR="Navy"]If[/COLOR] nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Set[/COLOR] nRng = Dn Else [COLOR="Navy"]Set[/COLOR] nRng = Union(nRng, Dn)
      .Item(Txt).Value = .Item(Txt).Value & ", " & Dn.Offset(, 2).Value
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]If[/COLOR] Not nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR] nRng.EntireRow.Delete
[COLOR="Navy"]End[/COLOR] With
Rng.Resize(, 4).Sort key1:=[A1], order1:=xlAscending, Header:=xlYes

[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
I am not sure why but I get the message "ActiveX component can't create Object. The line now highlighted in the macro is "With CreateObject ("scripting dictionary")".
Thank you.
 
Last edited:
Upvote 0
I just found out that since I am on Excel for Mac, that I don't have access to ActiveX. Is there maybe another way around this? Thanks again.
 
Upvote 0
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG08Jan10
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, nRng [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] temp [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Set[/COLOR] Rng = Range("A2", Range("A" & Rows.Count).End(xlUp))
Rng.Resize(, 4).Sort key1:=[A1], order1:=xlAscending, Header:=xlNo
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    Dn = Dn.Value & "," & Dn.Offset(, 1)
    [COLOR="Navy"]If[/COLOR] temp [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
        [COLOR="Navy"]Set[/COLOR] temp = Dn
    [COLOR="Navy"]Else[/COLOR]
            [COLOR="Navy"]If[/COLOR] Not temp = Dn [COLOR="Navy"]Then[/COLOR]
                [COLOR="Navy"]Set[/COLOR] temp = Dn
            [COLOR="Navy"]Else[/COLOR]
                [COLOR="Navy"]If[/COLOR] temp = Dn [COLOR="Navy"]Then[/COLOR]
                    temp.Offset(, 2).Value = temp.Offset(, 2).Value & "," & Dn.Offset(, 2).Value
                [COLOR="Navy"]End[/COLOR] If
                [COLOR="Navy"]If[/COLOR] nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Set[/COLOR] nRng = Dn Else [COLOR="Navy"]Set[/COLOR] nRng = Union(nRng, Dn)
            [COLOR="Navy"]End[/COLOR] If
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng: Dn = Split(Dn.Value, ",")(0): [COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]If[/COLOR] Not nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR] nRng.EntireRow.Delete
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Thanks again Mick. The macro works but doesn't do exactly what I need it to do. The group on the left is what your macro returned for me. Either one of the two on the left is what I really need. I have a much bigger data base that I need to reduce. Thanks again to you and all the members on this forum. It has been a big help to me in the past and is really appreciated.

<tbody>
</tbody>
FruitNumberSequenceShownFruitNumberSequenceShownFruitNumberSequenceShown
Apples#311Apples#17, 9, 113Apples#17, 9, 113
Apples#19,113Lemons#24, 62Apples#311
Apples #1 73Oranges#12, 52Lemons#24, 62
Lemons#24,62Pears#132Oranges#12, 52
Oranges#122Apples#311Oranges#2121
Oranges#1 52Oranges#2121Pears#132
Oranges#2121Pears#2101Pears#2101
Pears#131Plums#181Plums#181
Pears#2101
Plums#1 81

<colgroup><col width="65" span="14" style="width: 65pt;"></colgroup><tbody>
</tbody>

Thank you all so much
Larry
 
Last edited:
Upvote 0
Running my last code on your initial data returned the below to me !!!!
Was your data different ????
FruitNumberSequenceShown
Apples#311
Apples#17,9,113
Lemons#24,62
Oranges#12,52
Oranges#2121
Pears#131
Pears#2101
Plums#181
<colgroup><col width="108" style="width: 81pt; mso-width-source: userset; mso-width-alt: 3840;"> <col width="64" style="width: 48pt;" span="3"> <tbody> </tbody>
 
Last edited:
Upvote 0
Sorry Mick, I thought I posted this sooner but just saw my reply did not post. My data was the same as I posted before. Below is my data and on the left is your macro result. Everything seems to work except for the "Apples #1 " which didn't group together. Thanks again to you and all of the ones on the forum for all the help you have given me in the past. Again below is my list and on the right is the result of your macro.

FruitNumberSequenceShownFruitNumberSequenceShown
Apples#311Apples#311
Oranges#1 21Apples#1 9,113
Pears#1 31Apples #1 73
Lemons#242Lemons#24,62
Lemons#262Oranges#1 21
Apples #1 73Oranges#2121
Plums#1 81Pears#1 31
Apples#1 93Pears#2101
Pears#2101Plums#1 81
Apples#1 113
Oranges#2121

<colgroup><col width="65" span="9" style="width: 65pt;"></colgroup><tbody>
</tbody>
 
Upvote 0
Just out of curiosity, does this macro work for you (I don't have a Mac, so I cannot test it)...
Code:
[table="width: 500"]
[tr]
	[td]Sub SequenceNumbersPerFruitNumber()
  Dim R As Long, LastRow As Long, Arr As Variant
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  ReDim Arr(2 To LastRow, 1 To 1)
  For R = 2 To LastRow
    Arr(R, 1) = Application.Trim(Join(Application.Transpose(Evaluate(Replace("IF((A" & R & "=A2:A#)*(B" & R & "=B2:B#),C2:C#,"""")", "#", LastRow)))))
  Next
  Range("C2:C" & LastRow) = Arr
  Columns("A:D").RemoveDuplicates Array(1, 2, 3, 4), xlYes
  Columns("A:D").Sort [A1], xlAscending, Header:=xlYes
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Sorry, I wish I could say yes but I get the exact same results as Mick's macro except this macro runs for a really long time before it gives the results. I ran it twice to make sure. Thank you for trying, i really appreciate it.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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