Linking Adjacent Cells

jmd0103

New Member
Joined
Aug 28, 2012
Messages
10
I have a macro that moves cells in one order to another order. As these cells move is there any way to have the cells right next to each of them move along with them.

For example: My macro puts column 1 in numerical order....can I link column 2 to column 1 so that column 2 follows the new order of column 1?
[TABLE="class: grid, width: 500, align: left"]
<TBODY>[TR]
[TD]Column 1[/TD]
[TD]Column 2[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]cat[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]dog[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]horse[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]pig[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]elephant [/TD]
[/TR]
</TBODY>[/TABLE]
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi

I sorted your table (smalles to largest) with the macro recorder on.
Can you adjust the code to suit your needs?
Code:
Sub SortTable
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A2"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").Sort
        .SetRange Range("A2:B6")
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub

Vidar
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
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