0

Here is my code:

Sub SortData()
'
' SortData Macro
'

'
    Columns("A:A").Select
    Selection.SpecialCells(xlCellTypeBlanks).Select
    Selection.EntireRow.Delete
    Columns("A:A").Select
    Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
        :=":", FieldInfo:=Array(Array(1, 1), Array(2, 1))
    Columns("A:A").Select
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A1"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    Columns("A:A").Select
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A1"), _
        SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").Sort
        .SetRange Range("A2:C70")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub

It says the problem is in the fourth line from the top.

This macro is trying to reorganize simple data.

Any help would be much appreciated. Thanks!

Scott Craner
  • 148,073
  • 10
  • 49
  • 81
  • cell<>columns.... – Doug Coats Dec 07 '16 at 19:48
  • 2
    The fourth line from the top is an apostrophe.... – Mathieu Guindon Dec 07 '16 at 20:15
  • `Selection.SpecialCells(xlCellTypeBlanks).Select` will fail if no cells are found (i.e. the column is empty). Note that you should almost always avoid using the [global collections](http://stackoverflow.com/documentation/excel-vba/1107/vba-best-practices/9218/never-assume-the-worksheet#t=201612072122306662861), [`Activate`, and `Select`](http://stackoverflow.com/documentation/excel-vba/1107/vba-best-practices/9292/avoid-using-select-or-activate#t=201612072122306662861). This is also a [must read](http://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba-macros). – Comintern Dec 07 '16 at 21:24

0 Answers0