The following is a small scale of a data set I have in Excel:
Country State City Count Date
U.S. New York Albany 200 2/4/2013
U.S. New York Albany 200 1/6/2013
U.S. New York Albany 200 12/31/2012
U.S. New York Buffalo 10 4/10/2013
U.S. New York Buffalo 10 1/5/2013
U.S. Georgia Savannah 15 2/10/2013
U.S. Georgia Savannah 15 11/1/2012
U.S. Georgia Atlanta 500 12/5/2013
I would like to sort each state by date without changing the order the states are in. My customer has requested that the states be placed in a specific order that is not alpha or numeric.
I did attempt the following, but couldn't get it to work:
The autofilter functions properly, but I get the run-time error "The command you chose cannot be performed with multiple selections. Select a single range and click the command again."
I'm not determined to use this approach, so suggestions for alternatives would be gladly welcomed.
Country State City Count Date
U.S. New York Albany 200 2/4/2013
U.S. New York Albany 200 1/6/2013
U.S. New York Albany 200 12/31/2012
U.S. New York Buffalo 10 4/10/2013
U.S. New York Buffalo 10 1/5/2013
U.S. Georgia Savannah 15 2/10/2013
U.S. Georgia Savannah 15 11/1/2012
U.S. Georgia Atlanta 500 12/5/2013
I would like to sort each state by date without changing the order the states are in. My customer has requested that the states be placed in a specific order that is not alpha or numeric.
I did attempt the following, but couldn't get it to work:
Code:
Sub Sort_States_byDate()
Dim dataWS As Worksheet
Dim rowLimit As Integer
Dim colLimit As Integer
Dim a As Range
Set dataWS = ThisWorkbook.Sheets("Active")
Worksheets("Active").Activate
rowLimit = dataWS.UsedRange.Rows.Count
colLimit = dataWS.UsedRange.Columns.Count
Set a = Worksheets("Active").Range(Cells(1, 1), Cells(rowLimit, colLimit))
With Worksheets("Active")
a.AutoFilter Field:=2, Criteria1:="New York"
With Cells.SpecialCells(xlCellTypeVisible)
.Sort Key1:=Range("E1"), order1:=xlAscending
End With
End With
End Sub
The autofilter functions properly, but I get the run-time error "The command you chose cannot be performed with multiple selections. Select a single range and click the command again."
I'm not determined to use this approach, so suggestions for alternatives would be gladly welcomed.