Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Macro is choosing by tab name?

Hi Jim -- Thanks for your help! I am trying to get it to run against
whatever the current active sheet is. So, I tried to follow your email and I
changed to code to look like this:

Range("H2").Select
ActiveWorksheet.Sort.SortFields.Clear
ActiveWorksheet.Sort.SortFields.Add _
Key:=Range("H2"), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption _
:=xlSortTextAsNumbers
With ActiveWorksheet.Sort
.SetRange Range("A3:I45")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

but now it gives me a new error message when I run it:

error 424 "object required". When I debug, it highlights the following line:

ActiveWorksheet.Sort.SortFields.Clear

Ideas? I'm using Excel 2008, if you think that might make any difference.

Thanks!
Dawn

"Jim Thomlinson" wrote:

If you intend the code to be run against the active worksheet then change...

ActiveWorkbook.Worksheets("Docket_Report 1 ")
to
ActiveWorksheet

If you intend to run it against a specific sheet whose tab name changes then
you will need to specify the code name of the sheet. We can help you with
that if you need...
--
HTH...

Jim Thomlinson


"Dawn" wrote:

Hi -- I have a macro I recorded that's doing some formatting on a report.
One part of the macro is looking at the name of the worksheet, but it's not
always the same name. Is there any way to alter this code so it works no
matter what the worksheet name is? It really just needs to select a
particular column, I'm not sure why it's looking at the worksheet name at
all. Thanks for any advice!

-Dawn

ActiveWorkbook.Worksheets("Docket_Report 1 ").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Docket_Report 1 ").Sort.SortFields.Add _
Key:=Range("H2"), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption _
:=xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Docket_Report 1 ").Sort
.SetRange Range("A3:I45")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Choosing which macro to call NickHK Excel Programming 0 December 13th 06 02:46 AM
Choosing printer in a printing macro Werner[_18_] Excel Programming 1 July 5th 05 04:52 PM
Choosing printer in a printing macro \Jean-Jerome Doucet via OfficeKB.com\ Excel Programming 2 July 5th 05 04:31 PM
Help on choosing the right way Antonis Excel Programming 2 September 4th 04 08:45 PM
choosing from a list in VB Mary Agnes Excel Programming 0 February 5th 04 03:51 PM


All times are GMT +1. The time now is 04:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"