Name: Anonymous 2008-02-26 0:07
Ok, so I'm trying to use VBA to do some macros in excel. It's been about 4 years since I've messed with this and I used to know it really well but now I've pretty much forgotten it because this shit sucks. Anyways, what I want to do is go through every sheet in the workbook and select from cell A3 to the last used cell then sort on the value of the selected cells. With lots of googling and forcing myself to remember I came up with the following
Sub AutoSort()
Dim CurrentSheet As Worksheet
For Each CurrentSheet In Worksheets
Dim x As Long 'x = the last cell
x = CurrentSheet.Range("A65536").End(xlUp).Row
Worksheets(CurrentSheet.Name).Range(Cells(3, 1), Cells(x, 1)).Select
Next CurrentSheet
End Sub
All this is supposed to do is just select the shit I want selected, I haven't even gotten to the sorting yet (should be easy). The problem is it only works for the first worksheet then when it moves on to the second one it gives me a a run-time error 1004 "application-defined or object-defined error" and then stops.
tl;dr how do I select from A3 to the last used cell in column A for all my worksheets (assume the number of and names of the worksheets is unknown)?
Sub AutoSort()
Dim CurrentSheet As Worksheet
For Each CurrentSheet In Worksheets
Dim x As Long 'x = the last cell
x = CurrentSheet.Range("A65536").End(xlUp).Row
Worksheets(CurrentSheet.Name).Range(Cells(3, 1), Cells(x, 1)).Select
Next CurrentSheet
End Sub
All this is supposed to do is just select the shit I want selected, I haven't even gotten to the sorting yet (should be easy). The problem is it only works for the first worksheet then when it moves on to the second one it gives me a a run-time error 1004 "application-defined or object-defined error" and then stops.
tl;dr how do I select from A3 to the last used cell in column A for all my worksheets (assume the number of and names of the worksheets is unknown)?