Remove superfluous code from sort code

AndyEd

Board Regular
Joined
May 13, 2020
Messages
124
Office Version
  1. 365
Platform
  1. Windows
I'm trying to sort a column where there is a dynamic list.

I've tried numerous ways via the internet, but can't seem to get them to work. I've run this via a Macro but can't seem to clean it up.
Can anyone please help and explain how it works?

VBA Code:
    Columns("C:C").Select
    ActiveWorkbook.Worksheets("Validation sheet").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Validation sheet").Sort.SortFields.Add2 Key:=range _
        ("C2:C36"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal

    With ActiveWorkbook.Worksheets("Validation sheet").Sort
        .SetRange range("C1:C36")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Is it something like this? sort based in column C?

VBA Code:
Option Explicit
Sub test()
Dim ws As Worksheet
Set ws = Sheets("Validation Sheet")

With ws
    .[a2].Sort Key1:=.Range("c2"), order1:=xlAscending, Header:=xlYes
End With

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,140
Messages
6,123,266
Members
449,093
Latest member
Vincent Khandagale

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