Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

LOL VBA

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)?

Name: Anonymous 2008-02-26 0:09

Dim x As Long 'x = the last cell
Long 'x =
'x
(quote x)

???

Name: Anonymous 2008-02-26 0:11

Oh, sorry, that's just a comment on that line, without the comment it'd just read

Dim x As Long

Sorry for the confusion.

Name: Anonymous 2008-02-26 0:27

| Ok, so I'm trying to use VBA

I stopped reading right there.

Name: Anonymous 2008-02-26 0:45

| Ok, so I'm trying to use VBA
 
I stopped reading right there.

Name: Anonymous 2008-02-26 2:13

Visual Boy Advance is the shit.

Name: Anonymous 2008-02-26 4:16

>>5
| OK, so I'm trying to use VBA

BBCode double quote FAIL

Name: Anonymous 2008-02-26 18:35

i do all my office automation now with C# has all the same functions and stuff

Name: Henri Leconte 2011-03-01 23:10

sandbox

Name: Anonymous 2011-03-01 23:33

>>1
then when it moves on to the second one
Where exactly does the error happen?

Name: Anonymous 2011-03-02 2:50

>>10
>>1
2008

Don't change these.
Name: Email:
Entire Thread Thread List