this is a hybrid solutions.
your data like this from A1 to B7(one more set added for check
<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} table.MsoTableGrid {mso-style-name:"Table Grid"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; border:solid windowtext 1.0pt; mso-border-alt:solid windowtext .5pt; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-border-insideh:.5pt solid windowtext; mso-border-insidev:.5pt solid windowtext; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]--> <table class="MsoTableGrid" style="border-collapse:collapse;border:none;mso-border-alt:solid windowtext .5pt; mso-yfti-tbllook:480;mso-padding-alt:0in 5.4pt 0in 5.4pt;mso-border-insideh: .5pt solid windowtext;mso-border-insidev:.5pt solid windowtext" border="1" cellpadding="0" cellspacing="0"> <tbody><tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes"> <td style="width:221.4pt;border:solid windowtext 1.0pt; mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt" valign="top" width="295"> hdng1
</td> <td style="width:221.4pt;border:solid windowtext 1.0pt; border-left:none;mso-border-left-alt:solid windowtext .5pt;mso-border-alt: solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt" valign="top" width="295"> hdng2
</td> </tr> <tr style="mso-yfti-irow:1"> <td style="width:221.4pt;border:solid windowtext 1.0pt; border-top:none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt; padding:0in 5.4pt 0in 5.4pt" valign="top" width="295">
</td> <td style="width:221.4pt;border-top:none;border-left: none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt; mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt; mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt" valign="top" width="295"> hat
</td> </tr> <tr style="mso-yfti-irow:2"> <td style="width:221.4pt;border:solid windowtext 1.0pt; border-top:none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt; padding:0in 5.4pt 0in 5.4pt" valign="top" width="295"> car
</td> <td style="width:221.4pt;border-top:none;border-left: none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt; mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt; mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt" valign="top" width="295"> hat
</td> </tr> <tr style="mso-yfti-irow:3"> <td style="width:221.4pt;border:solid windowtext 1.0pt; border-top:none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt; padding:0in 5.4pt 0in 5.4pt" valign="top" width="295">
</td> <td style="width:221.4pt;border-top:none;border-left: none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt; mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt; mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt" valign="top" width="295"> hat
</td> </tr> <tr style="mso-yfti-irow:4"> <td style="width:221.4pt;border:solid windowtext 1.0pt; border-top:none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt; padding:0in 5.4pt 0in 5.4pt" valign="top" width="295">
</td> <td style="width:221.4pt;border-top:none;border-left: none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt; mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt; mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt" valign="top" width="295"> rat
</td> </tr> <tr style="mso-yfti-irow:5"> <td style="width:221.4pt;border:solid windowtext 1.0pt; border-top:none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt; padding:0in 5.4pt 0in 5.4pt" valign="top" width="295">
</td> <td style="width:221.4pt;border-top:none;border-left: none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt; mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt; mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt" valign="top" width="295"> rat
</td> </tr> <tr style="mso-yfti-irow:6;mso-yfti-lastrow:yes"> <td style="width:221.4pt;border:solid windowtext 1.0pt; border-top:none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt; padding:0in 5.4pt 0in 5.4pt" valign="top" width="295"> Train
</td> <td style="width:221.4pt;border-top:none;border-left: none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt; mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt; mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt" valign="top" width="295"> rat
</td> </tr> </tbody></table>
now run this macro
Code:
Sub find_sets()
Dim r As Range, c As Range
Set r = Range(Range("A2"), Cells(Rows.Count, "B").End(xlUp).Offset(0, -1))
For Each c In r
If c <> "" Then
Range(c, c.Offset(0, 1)).Copy Cells(Rows.Count, "G").End(xlUp).Offset(1, 0)
End If
Next
Range("A1:B1").Copy Range("G1")
End Sub
Code:
you will get from G1 to H3 as follows
<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]--> <table class="MsoNormalTable" style="width:96.0pt;margin-left:4.65pt;border-collapse:collapse;mso-padding-alt: 0in 5.4pt 0in 5.4pt" width="128" border="0" cellpadding="0" cellspacing="0"> <tbody><tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;height:12.75pt"> <td style="width:48.0pt;padding:0in 5.4pt 0in 5.4pt; height:12.75pt" valign="bottom" width="64" nowrap="nowrap"> [FONT=Arial]hdng1[/FONT]
</td> <td style="width:48.0pt;padding:0in 5.4pt 0in 5.4pt; height:12.75pt" valign="bottom" width="64" nowrap="nowrap"> [FONT=Arial]hdng2[/FONT][FONT=Arial][/FONT]
</td> </tr> <tr style="mso-yfti-irow:1;height:12.75pt"> <td style="width:48.0pt;padding:0in 5.4pt 0in 5.4pt; height:12.75pt" valign="bottom" width="64" nowrap="nowrap"> [FONT=Arial]car[/FONT]
</td> <td style="width:48.0pt;padding:0in 5.4pt 0in 5.4pt; height:12.75pt" valign="bottom" width="64" nowrap="nowrap"> [FONT=Arial]hat[/FONT]
</td> </tr> <tr style="mso-yfti-irow:2;mso-yfti-lastrow:yes;height:12.75pt"> <td style="width:48.0pt;padding:0in 5.4pt 0in 5.4pt; height:12.75pt" valign="bottom" width="64" nowrap="nowrap"> [FONT=Arial]Train[/FONT]
</td> <td style="width:48.0pt;padding:0in 5.4pt 0in 5.4pt; height:12.75pt" valign="bottom" width="64" nowrap="nowrap"> [FONT=Arial]rat[/FONT]
</td> </tr> </tbody></table>
now goto A2 and type this formula
=INDEX($G$2:$G$100,MATCH(B2,$H$2:$H$100,0),1)
copy A2 down.
you will get
<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]--> <table class="MsoNormalTable" style="width:96.0pt;margin-left:4.65pt;border-collapse:collapse;mso-padding-alt: 0in 5.4pt 0in 5.4pt" width="128" border="0" cellpadding="0" cellspacing="0"> <tbody><tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;height:12.75pt"> <td style="width:48.0pt;padding:0in 5.4pt 0in 5.4pt; height:12.75pt" valign="bottom" width="64" nowrap="nowrap"> [FONT=Arial]hdng1[/FONT]
</td> <td style="width:48.0pt;padding:0in 5.4pt 0in 5.4pt; height:12.75pt" valign="bottom" width="64" nowrap="nowrap"> [FONT=Arial]hdng2[/FONT]
</td> </tr> <tr style="mso-yfti-irow:1;height:12.75pt"> <td style="width:48.0pt;padding:0in 5.4pt 0in 5.4pt; height:12.75pt" valign="bottom" width="64" nowrap="nowrap"> [FONT=Arial]car[/FONT]
</td> <td style="width:48.0pt;padding:0in 5.4pt 0in 5.4pt; height:12.75pt" valign="bottom" width="64" nowrap="nowrap"> [FONT=Arial]hat[/FONT]
</td> </tr> <tr style="mso-yfti-irow:2;height:12.75pt"> <td style="width:48.0pt;padding:0in 5.4pt 0in 5.4pt; height:12.75pt" valign="bottom" width="64" nowrap="nowrap"> [FONT=Arial]car[/FONT]
</td> <td style="width:48.0pt;padding:0in 5.4pt 0in 5.4pt; height:12.75pt" valign="bottom" width="64" nowrap="nowrap"> [FONT=Arial]hat[/FONT]
</td> </tr> <tr style="mso-yfti-irow:3;height:12.75pt"> <td style="width:48.0pt;padding:0in 5.4pt 0in 5.4pt; height:12.75pt" valign="bottom" width="64" nowrap="nowrap"> [FONT=Arial]car[/FONT]
</td> <td style="width:48.0pt;padding:0in 5.4pt 0in 5.4pt; height:12.75pt" valign="bottom" width="64" nowrap="nowrap"> [FONT=Arial]hat[/FONT]
</td> </tr> <tr style="mso-yfti-irow:4;height:12.75pt"> <td style="width:48.0pt;padding:0in 5.4pt 0in 5.4pt; height:12.75pt" valign="bottom" width="64" nowrap="nowrap"> [FONT=Arial]Train[/FONT]
</td> <td style="width:48.0pt;padding:0in 5.4pt 0in 5.4pt; height:12.75pt" valign="bottom" width="64" nowrap="nowrap"> [FONT=Arial]rat[/FONT]
</td> </tr> <tr style="mso-yfti-irow:5;height:12.75pt"> <td style="width:48.0pt;padding:0in 5.4pt 0in 5.4pt; height:12.75pt" valign="bottom" width="64" nowrap="nowrap"> [FONT=Arial]Train[/FONT]
</td> <td style="width:48.0pt;padding:0in 5.4pt 0in 5.4pt; height:12.75pt" valign="bottom" width="64" nowrap="nowrap"> [FONT=Arial]rat[/FONT]
</td> </tr> <tr style="mso-yfti-irow:6;mso-yfti-lastrow:yes;height:12.75pt"> <td style="width:48.0pt;padding:0in 5.4pt 0in 5.4pt; height:12.75pt" valign="bottom" width="64" nowrap="nowrap"> [FONT=Arial]Train[/FONT]
</td> <td style="width:48.0pt;padding:0in 5.4pt 0in 5.4pt; height:12.75pt" valign="bottom" width="64" nowrap="nowrap"> [FONT=Arial]rat[/FONT]
</td> </tr> </tbody></table>
is it ok?(upto 100 rows in colA and B. if more modify the formula