LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default Onclick 2 events

Steve Jackson wrote:
Private Sub CommandButton1_Click()
Sheets("Tables").Select
Range("B2:J6").Select
Selection.Sort Key1:=Range("J3"), Order1:=xlDescending,
Key2:=Range("I3") _
, Order2:=xlDescending, Header:=xlGuess, OrderCustom:=1,
MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal


Steve:

There are two problems. First, you are trying to select a range, B2:J6,
that's not on the active sheet. The difference between this code and the
code you copied from is location. When you're in a class module, like the
module where you code events for sheets, the default object is the sheet
whose class module you're in, not the active sheet. If you're in a standard
module, the active sheet is the default object. You need to prefix your
Ranges with the sheet reference. See also the "Default Object" section on
this page

http://www.dailydoseofexcel.com/arch...-object-model/

Second, you don't really need to select the range before you sort it. You
could, for instance, say

With Sheets("Table").Range("B2:J6")
.Sort Key1:= etc...
End With

For more information on selecting and activating, see

http://www.dailydoseofexcel.com/arch...-and-activate/

--
Dick Kusleika
MS MVP - Excel
www.dailydoseofexcel.com


 
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
OnClick [email protected] Excel Discussion (Misc queries) 1 August 31st 06 06:08 PM
OnClick event lilika Excel Programming 2 February 22nd 05 05:34 PM
onClick in Excel Nicole Excel Programming 3 January 25th 05 09:45 AM
onclick event for cell ties Excel Programming 4 July 20th 04 12:09 PM
range onclick? Dennis Excel Programming 2 November 23rd 03 07:34 PM


All times are GMT +1. The time now is 09:41 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"