0
Sub SortDataWithoutHeader()
Range("A1", Range("A1").End(xlDown)).Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlNo
End Sub

my interface buttons are in a sheet called 'tools' and the data being manipulated is in a sheet called 'data'

2
  • 2
    Anywhere you have a Range call, add ThisWorkbook.Worksheets("Data"). beforehand. Commented Jul 9, 2020 at 13:31
  • It gives me "Runtime error 1004 - Application-defined or Object-defined error. Screenshot imgur.com/kYKKfKV Commented Jul 9, 2020 at 13:45

1 Answer 1

1

Something like this. A With statement can be helpful here. Note the periods before every Range, Cells, and Rows call within the With block. The period is necessary to actually reference ws, which is the sheet you want.

Sub SortDataWithoutHeader()
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Worksheets("Data")
    
    With ws
        Dim lastRow As Long
        lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        
        .Range("A1:A" & lastRow).Sort Key1:=.Range("A1"), Order1:=xlAscending, Header:=xlNo
    End With
End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.