syntax for a data sort

OutlawoftheMarsh

New Member
Joined
Dec 11, 2003
Messages
35
I'm on Sheet1. I need to sort the data on Sheet2 without leaving Sheet1. When Sheet2 is the active sheet, my macro runs fine. When Sheet 1 is the active sheet, I get a 1004 error. I have no idea what that means. Here's my code:

Sheets("Sheet2").Columns("A:C").Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

I'm not sure which part is wrong, but I think it might have something to do with the Range("A1") part.

Thanks,

Outlaw
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
In my testing, I wasn't able to sort a range not on the active sheet. There might very well be a way, I just didn't find it.

Just out of curiousity, why can't you go to Sheet2, sort it, and then go back?
 
Upvote 0
Is that all of your code?

I think you might want to make a reference to the sheet you want to sort:

Sheets("Sheet2").Columns("A:C").Sort Key1:=Sheets("Sheet2").Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
 
Upvote 0
Thanks, Norie. Your suggestion fixed it perfectly. I thought I had the syntax wrong, but my help files are missing, so it's tough.

In response to Tazguy's question, I am creating a workbook to help with learning new vocabulary (among other things). It's kind of like electronic flashcards. As such, I'm going to be sorting the data again and again in relatively rapid succession, so it would give me a headache watching the screen switch back and forth so much. I guess I could put the vocab list way off to the right somewhere on one worksheet and put the "flashcard" on there on the left, but I prefer having different pages (and learning more about VBA).

Thanks again for the help!

Outlaw of the Marsh
 
Upvote 0
With Application.ScreenUpdating set to false, you wouldn't see the windows going back and forth.
 
Upvote 0

Forum statistics

Threads
1,214,386
Messages
6,119,214
Members
448,874
Latest member
b1step2far

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top