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:

1215a
1517b
1710c
1612d
1016e

<tbody>
</tbody>

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:

1212d
1515a
1717b
1616e
1010c

<tbody>
</tbody>

Is there a way to do this??


****** id="cke_pastebin" style="position: absolute; top: 0px; width: 1px; height: 1px; overflow: hidden; left: -1000px;">
1215a
1517b
1710c
1612d
1016d

<tbody>
</tbody>

</body>
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
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,214,789
Messages
6,121,590
Members
449,039
Latest member
Arbind kumar

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