Explain Code

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
1,835
Office Version
  1. 365
Platform
  1. Windows
I know that this code is creating a list of all the tab names and listing them starting in Row 16 column A

I see that it is supposed to sort the list. But what is line of code below doing? Why ("A6:A9")? What is this line doing or its purpose

ActiveWorkbook.Worksheets("Archive").Sort.SortFields.Add Key:=Range("A6:A9"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Archive").Sort

Code:
Sub Create_Archive()

Dim i As Integer
For i = 1 To ThisWorkbook.Sheets.Count
Sheet15.Cells(i + 15, 1) = Sheets(i).Name
Next i
'Sort the Tab Names
    Sheet15.Range("A16:A665").Select
    ActiveWorkbook.Worksheets("Archive").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Archive").Sort.SortFields.Add Key:=Range("A6:A9"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Archive").Sort
        .SetRange Range("A16:A665")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub

Thanks for the help
 

Some videos you may like

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
48,400
Office Version
  1. 365
Platform
  1. Windows
Why ("A6:A9")? What is this line doing or its purpose
Looks to me like a remnant from a recorded macro that didn't get tidied up. Same with Sheet15.Range("A16:A665").Select
Basically it is just saying that the Sort is sorting on column A
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,127,847
Messages
5,627,239
Members
416,232
Latest member
Ash1432

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
Top