Macro that aligns 8 columns

llangid

New Member
Joined
Mar 15, 2011
Messages
15
I am sure this can be done with a macro but I not having any luck at all creating one or finding one so I am hoping someone here can help me.


I have 8 columns that need to be aligned and make one master column that four of the columns align to. Let’s say column B, D F and H have the numbers in them that need to be aligned in rows with each other and columns C, E, G, and H each need to stay with the preceding column. So columns BC, DE, FG, and HI need to stay together as the alignment happens.



There are common numbers between columns B, D, F, and H that need to be matched and there could be duplicates in any one of the groups of columns (group BC, group DE, group FG, and group HI) and the column groups are of different lengths .


As the columns are aligned the number that is put into column A becomes the master column for all the numbers in the rows.


Thanks in advance for your help.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hi,

Welcome to MrExcel.

Try the following macro code on some test data and see if it works for you.

It gives the aligned rows in sorted order, coz I wasn't sure about your master column. Can easily be modified tho' if you specify how you want it.
Code:
Sub lineemup()
Dim nr As Long, j As Long, k As Long
Application.ScreenUpdating = False
nr = Range("B:I").Find("*", searchorder:=xlByRows, _
    searchdirection:=xlPrevious).Row
For j = 2 To 8 Step 2
    Cells(1, j).Resize(nr).Sort Cells(1, j), 1
Next j
Do
k = k + 1
With Cells(1, Columns.Count)
    .Resize(8).ClearContents
For j = 2 To 8 Step 2
    .Offset(j - 1) = Cells(k, j).Value
Next j
    .Resize(8).Sort .Resize(1), 1
For j = 2 To 8 Step 2
    If Len(Cells(k, j)) > 0 And _
        Cells(k, j) <> .Value Then Cells(k, j).Resize(, 2).Insert xlDown
Next j
End With
Loop Until Application.CountA(Range("B1").Resize(, 8).Offset(k)) = 0
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Mirabeau

The code works perfectly :)

For the master column I want the number of whatever is in that row. So if in row 1 column b is empty column d has number 12543 in it and column f and h are empty then column A (master column) would also has 12543 in it. Then that would just be repeated all the way down sheet for every row.

Thank you very much I really appreciate your help.
 
Upvote 0
OK. Glad that it works and does what you want.

I'm still not clear about what the master column is supposed to do though.

However, maybe you can organize whatever you want yourself.
 
Upvote 0
Mirabeau

Yea adding the master column up front is a simple Min formula and I can easily do that.

Once again thanks for your help I really appreciate it.:)
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,551
Members
452,927
Latest member
rows and columns

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