Align duplicated values and string another column

migliozm

New Member
Joined
Feb 2, 2018
Messages
1
Hi everyone,

I am having trouble aligning multiple columns. For instance, I have this:

[TABLE="width: 500"]
<tbody>[TR]
[TD]12[/TD]
[TD]15[/TD]
[TD]a[/TD]
[/TR]
[TR]
[TD]15[/TD]
[TD]17[/TD]
[TD]b[/TD]
[/TR]
[TR]
[TD]17[/TD]
[TD]10[/TD]
[TD]c[/TD]
[/TR]
[TR]
[TD]16[/TD]
[TD]12[/TD]
[TD]d[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]16[/TD]
[TD]e[/TD]
[/TR]
</tbody>[/TABLE]

And I need to keep the values in the second and third columns together but align the duplicates in columns 1 and 2 like this:

[TABLE="width: 500"]
<tbody>[TR]
[TD]12[/TD]
[TD]12[/TD]
[TD]d[/TD]
[/TR]
[TR]
[TD]15[/TD]
[TD]15[/TD]
[TD]a[/TD]
[/TR]
[TR]
[TD]17[/TD]
[TD]17[/TD]
[TD]b[/TD]
[/TR]
[TR]
[TD]16[/TD]
[TD]16[/TD]
[TD]e[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]10[/TD]
[TD]c[/TD]
[/TR]
</tbody>[/TABLE]

Is there a way to do this??


****** id="cke_pastebin" style="position: absolute; top: 0px; width: 1px; height: 1px; overflow: hidden; left: -1000px;">[TABLE="width: 500"]
<tbody>[TR]
[TD]12[/TD]
[TD][/TD]
[TD]15[/TD]
[TD]a[/TD]
[/TR]
[TR]
[TD]15[/TD]
[TD][/TD]
[TD]17[/TD]
[TD]b[/TD]
[/TR]
[TR]
[TD]17[/TD]
[TD][/TD]
[TD]10[/TD]
[TD]c[/TD]
[/TR]
[TR]
[TD]16[/TD]
[TD][/TD]
[TD]12[/TD]
[TD]d[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD][/TD]
[TD]16[/TD]
[TD]d[/TD]
[/TR]
</tbody>[/TABLE]

</body>
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Try this:

Code:
Sub AllignToFirstCol()
Dim WB As Workbook, WS As Worksheet
Dim x As Integer, RW As Integer, y As Integer
Dim alist As Variant
Dim blist As Variant
Dim Chk As Variant 'you can change data type to be more specific to what you have


Set WB = ThisWorkbook
Set WS = WB.Sheets("Sheet2") 'your worksheet name


RW = WS.Range("B3").End(xlDown).Row


ReDim alist(0 To RW - 1)
ReDim blist(0 To RW - 1)


For x = 1 To RW
    alist(x - 1) = WS.Range("B1").Offset(x - 1).Value
    blist(x - 1) = WS.Range("C1").Offset(x - 1).Value
Next x


For x = 1 To RW
    Chk = WS.Range("A1").Offset(x - 1).Value
        For y = 1 To RW
            If alist(y - 1) = Chk Then
            WS.Range("B1").Offset(x - 1).Value = alist(y - 1)
            WS.Range("C1").Offset(x - 1).Value = blist(y - 1)
            Exit For
            End If
        Next y
Next x
End Sub

Hopefully your columns are in A:A,B:B,C:C - and dont forget to change sheet name to what you have
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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