Extract text from one row to unique row

dragonlwc

New Member
Joined
May 16, 2016
Messages
5
What I want to do is to extract data from one row and copy it to unique row
What function can be used so that the result like below one

Before

NameSubjectGrade
TomMathA
MaryEngC
PeterPhyD
MaryChemB
TomBioB
JohnMathC

<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>
</tbody>


After

NameSubjectGrade
TomMathABioB
MaryEngCChemB
PeterPhyD
JohnMathC

<colgroup><col width="64" span="5" style="width:48pt"> </colgroup><tbody>
</tbody>
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try this for Results on sheet 2.
Code:
[COLOR="Navy"]Sub[/COLOR] MG16May09
[COLOR="Navy"]Dim[/COLOR] RAY [COLOR="Navy"]As[/COLOR] Variant, c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Q [COLOR="Navy"]As[/COLOR] Variant, oMax [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Dic [COLOR="Navy"]As[/COLOR] Object
RAY = ActiveSheet.Range("A1").CurrentRegion.Resize(, 3)
ReDim nray(1 To UBound(RAY, 1), 1 To 3)
[COLOR="Navy"]Set[/COLOR] Dic = CreateObject("scripting.dictionary")
Dic.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] n = 1 To UBound(RAY, 1)
    [COLOR="Navy"]If[/COLOR] Not Dic.exists(RAY(n, 1)) [COLOR="Navy"]Then[/COLOR]
        c = c + 1
        nray(c, 1) = RAY(n, 1)
        nray(c, 2) = RAY(n, 2)
        nray(c, 3) = RAY(n, 3)
        Dic.Add RAY(n, 1), Array(c, 3)
[COLOR="Navy"]Else[/COLOR]
    Q = Dic.Item(RAY(n, 1))
         Q(1) = Q(1) + 2
         [COLOR="Navy"]If[/COLOR] UBound(nray, 2) <= Q(1) [COLOR="Navy"]Then[/COLOR] ReDim Preserve nray(1 To UBound(RAY, 1), 1 To Q(1))
         nray(Q(0), Q(1) - 1) = RAY(n, 2)
         nray(Q(0), Q(1)) = RAY(n, 3)
         nray(1, Q(1) - 1) = "Subject"
         nray(1, Q(1)) = "Grade"
         oMax = Application.Max(oMax, Q(1))
    Dic.Item(RAY(n, 1)) = Q
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] n
Sheets("Sheet2").Range("A1").Resize(c, oMax) = nray

[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Bummer, posted my solution before I was alerted that this was a cross post.

Extract text from one row and copy to unique row

Oh well, here's my attempt:

<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit;">Sub chau()
Set ws1 = Sheets("Sheet1")
Set ws2 = Sheets.Add(, Sheets(Sheets.Count))
ws1.Columns(1).AdvancedFilter xlFilterCopy, , ws2.[A1], True
With ws1.Columns(1)
For Each n In ws2.Columns(1).SpecialCells(2)
c = 2
Set d = .Find(n.Value)
f = d.Address
Do
d.Offset(0, 1).Resize(1, 2).Copy ws2.Cells(n.Row, c)
c = c + 2
Set d = .FindNext(d)
Loop While Not d Is Nothing And d.Address <> f
Next
End With
End Sub</code>
 
Upvote 0
Hi dragonlwc
Welcome to the board

Cross-post???

That's really rude. You won't get many friends like this.
 
Upvote 0

Forum statistics

Threads
1,215,086
Messages
6,123,040
Members
449,092
Latest member
ikke

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