excel 2003 make code sheet specific

User avatar
Bigger312
StarLounger
Posts: 51
Joined: 12 Mar 2012, 16:42
Location: Dublin, Ireland

excel 2003 make code sheet specific

Post by Bigger312 »

Hi,

The code below is working on the active sheet and I want to get it to work on Worksheet("patrol") I know that I must change Range to .Range but this is giving me an error which states.
Application-defined or object-defined error.

Thanks in advance for your time.

Gerry

Code: Select all

With Worksheets("Patrol")
 
Dim f As Long
   
   For f = 2 To 20 Step 3
        Range(Cells(1, f), Cells(33, f + 2)).Sort _
            Key1:=Cells(1, f + 1), Key2:=Cells(1, f + 2), _
            Header:=xlYes
    Next f
End With

User avatar
StuartR
Administrator
Posts: 12615
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: excel 2003 make code sheet specific

Post by StuartR »

Replace each instance of Cells with .Cells
StuartR


User avatar
Bigger312
StarLounger
Posts: 51
Joined: 12 Mar 2012, 16:42
Location: Dublin, Ireland

Re: excel 2003 make code sheet specific

Post by Bigger312 »

Will Do, Thanks

I played around with the code but could not get my . lined up.

Again Thanks

Gerry

User avatar
Bigger312
StarLounger
Posts: 51
Joined: 12 Mar 2012, 16:42
Location: Dublin, Ireland

Re: excel 2003 make code sheet specific

Post by Bigger312 »

Tried that and now works perfectly.

Gerry

User avatar
StuartR
Administrator
Posts: 12615
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: excel 2003 make code sheet specific

Post by StuartR »

Great, thanks for letting us know.
StuartR