Chris Macro
Well-known Member
- Joined
- Nov 2, 2011
- Messages
- 1,345
- Office Version
- 365
- Platform
- Windows
Is there any way to simplify this code?
Steps:
1. put in filter on table (specified by range)
2. sort alphabetically on column A
3. take off filter
Code:
<font face=Calibri><SPAN style="color:#007F00">'Sort Table 1 Alphabetically</SPAN><br>LastRow_T1 = Sheet5.Cells(Rows.Count, "A").End(xlUp).Row<br><br>Sheet5.Range("A4:L" & LastRow_T1).AutoFilter<br> Sheet5.AutoFilter.Sort.SortFields.Clear<br> Sheet5.AutoFilter.Sort.SortFields.Add Key _<br> :=Sheet5.Range("A4:A" & LastRow_T1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _<br> :=xlSortTextAsNumbers<br> <SPAN style="color:#00007F">With</SPAN> Sheet5.AutoFilter.Sort<br> .Header = xlYes<br> .MatchCase = <SPAN style="color:#00007F">False</SPAN><br> .Orientation = xlTopToBottom<br> .SortMethod = xlPinYin<br> .Apply<br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br> Sheet5.Range("A4:L4").AutoFilter</FONT>
Steps:
1. put in filter on table (specified by range)
2. sort alphabetically on column A
3. take off filter
Code:
<font face=Calibri><SPAN style="color:#007F00">'Sort Table 1 Alphabetically</SPAN><br>LastRow_T1 = Sheet5.Cells(Rows.Count, "A").End(xlUp).Row<br><br>Sheet5.Range("A4:L" & LastRow_T1).AutoFilter<br> Sheet5.AutoFilter.Sort.SortFields.Clear<br> Sheet5.AutoFilter.Sort.SortFields.Add Key _<br> :=Sheet5.Range("A4:A" & LastRow_T1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _<br> :=xlSortTextAsNumbers<br> <SPAN style="color:#00007F">With</SPAN> Sheet5.AutoFilter.Sort<br> .Header = xlYes<br> .MatchCase = <SPAN style="color:#00007F">False</SPAN><br> .Orientation = xlTopToBottom<br> .SortMethod = xlPinYin<br> .Apply<br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br> Sheet5.Range("A4:L4").AutoFilter</FONT>