Sort table column left to right

gaudrco

Board Regular
Joined
Aug 16, 2019
Messages
203
Is there way to sort table columns left to right? That is, the column headers sort alphabetically along with all the data below the headers. But here's the catch; I need just a selection of columns sorted.

My table ("CompComparisonTable") has competitors as the column headers and with features as the rows. So the first column are features going down the rows and the second and third column have to do with my company so I want these to remain farthest left. Everything to the right of that are competitors. Right now, the spreadsheet is set up to have new competitors added to the end of the table, but after they are added, I would like the new competitor to sort alphabetically with the other competitors.

Any ideas?
 
Select G5 and go down the column using the down arrow.
Anything merged ?
I have unmerged all cells on that sheet (i think) and still no luck

Did you see my response at your other thread and try it to see what Excel is seeing as the range ?
Yes, I have checked this and the range is exactly what I am looking for.

Do you think the "List of Values" report list is causing a problem?
 
Last edited:
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Yes, I have checked this and the range is exactly what I am looking for.
How did you check this ?
The Name Manager will indicate what you want, but
did you type the name into the name box on the formula bar and see the result that's selected ?
 
Upvote 0
did you type the name into the name box on the formula bar and see the result that's selected ?
Yes I did this.

I mentioned before but I will point it out again. The sorting for this range ("DynamicDataList") does work if I assign the code to a button and place the button on that sheet ("Competitor Comparison Data").
It looks like this:
Code:
Private Sub CommandButton3_Click()
Range("DynamicDataList").Sort Key1:=Range("DynamicDataList"), Order1:=xlAscending, Header:=xlYes, Orientation:=xlLeftToRight
End Sub

When I click this button, the sorting works
 
Last edited:
Upvote 0
Only difference I can see would be the sheet that's active at the time.
Any use of Range without the dot will refer to the active sheet.
Using .Range inside the With will refer to whatever the with is and without the dot will refer to the active sheet.
 
Upvote 0
Only difference I can see would be the sheet that's active at the time.
Any use of Range without the dot will refer to the active sheet.
Using .Range inside the With will refer to whatever the with is and without the dot will refer to the active sheet.

Code:
Private Sub CommandButton1_Click()


Set srtA = Sheets("Competitor Comparison")


With srtA
.ListObjects(1).Unlist
Range("DynamicCompList").Sort Key1:=Range("DynamicCompList"), Order1:=xlAscending, Header:=xlYes, Orientation:=xlLeftToRight
ActiveSheet.ListObjects.Add(xlSrcRange, Range("DynamicCompTable"), , xlYes).Name = _
        "CompComparisonTable"
        
 Range("A8").Select


 Selection.AutoFilter
End With


Set srtB = Sheets("Competitor Comparison Data")
With srtB
[B].Range("DynamicDataList").Sort Key1:=Range("DynamicDataList"), Order1:=xlAscending, Header:=xlYes, Orientation:=xlLeftToRight[/B]
End With
End Sub

Yeah I'm not sure whats going on here. I would bet it's something simple. The bold line is the line where this error comes up "Run-time error '1004': Method 'Range' of object '_Worksheet' failed"
 
Upvote 0
What if you put a dot in front of the other use of Range in that line ?
 
Upvote 0
I knew it was something simple! That suggestion makes logical sense to what you were saying here in post 34:
Any use of Range without the dot will refer to the active sheet.
Using .Range inside the With will refer to whatever the with is and without the dot will refer to the active sheet.

Thank you very much!
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,429
Members
448,961
Latest member
nzskater

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