PC Review


Reply
Thread Tools Rate Thread

boolean to control sort order

 
 
Ken
Guest
Posts: n/a
 
      31st Oct 2008
Sorry about previous post, I did something spastic and posted
prematurely

I am trying to use a boolean variable to control a sort Order. This
is a sort that is triggered by the double click event and I want to
toggle between Ascending and Decending in successive sorts. I can
get
it to work when my variable a string that is toggled between
xlAscending and xlDecending, I can get it to work when the variable
is
and integer toggled between 1 and 2, and I can get it to work when my
variable is Boolean equal to True. False causes and error. I would
like to simplify my already pretty simple code to

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel
As Boolean)
Range("DB_Cost_Report").Sort Key1:=Target.Offset(3, 0),
Order1:=True, Header:=xlfalse, _
OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ord = Not (ord)
Cancel = True
End Sub

ord is a global variable stored in a regular code module; since it
seems that I can't store a global variable in a worksheet module.

Is it not possible to control the order with a boolean, or am I
missing something.

Thanks

Ken
 
Reply With Quote
 
 
 
 
Ken
Guest
Posts: n/a
 
      31st Oct 2008
Okay, so I am a spastic idiot; the first time I posted prematurely,
the second time as soon as I sent it I realized my mistake. Since
False corresponds to zero, not 2, which is what I need for a decending
sort, of course it fails. True works fine because it corresponds to 1
which gives me the ascending sort. I guess a couple lines of code to
handle my 1 to 2 to 1 toggle won't be too bad.

Thanks

Ken
 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      31st Oct 2008
I for one would be more inclined to help if your offensive comment in this
post had not been included. Others may still be willing to

Mike


"Ken" wrote:

> Sorry about previous post, I did something spastic and posted
> prematurely
>
> I am trying to use a boolean variable to control a sort Order. This
> is a sort that is triggered by the double click event and I want to
> toggle between Ascending and Decending in successive sorts. I can
> get
> it to work when my variable a string that is toggled between
> xlAscending and xlDecending, I can get it to work when the variable
> is
> and integer toggled between 1 and 2, and I can get it to work when my
> variable is Boolean equal to True. False causes and error. I would
> like to simplify my already pretty simple code to
>
> Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel
> As Boolean)
> Range("DB_Cost_Report").Sort Key1:=Target.Offset(3, 0),
> Order1:=True, Header:=xlfalse, _
> OrderCustom:=1, MatchCase:=False,
> Orientation:=xlTopToBottom, _
> DataOption1:=xlSortNormal
> ord = Not (ord)
> Cancel = True
> End Sub
>
> ord is a global variable stored in a regular code module; since it
> seems that I can't store a global variable in a worksheet module.
>
> Is it not possible to control the order with a boolean, or am I
> missing something.
>
> Thanks
>
> Ken
>

 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      31st Oct 2008
sortOrder = xlAscending
or
sortOrder = xlDescending

These parameter are really constant numbers store in Excel. You can assign
them to variables. I used blow in the sort SortOrder instead of xlAscending
or xlDescending



Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel
As Boolean)
Range("DB_Cost_Report").Sort Key1:=Target.Offset(3, 0),
Order1:=sortOrder, Header:=xlfalse, _
OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ord = Not (ord)
Cancel = True
End Sub



"Ken" wrote:

> Okay, so I am a spastic idiot; the first time I posted prematurely,
> the second time as soon as I sent it I realized my mistake. Since
> False corresponds to zero, not 2, which is what I need for a decending
> sort, of course it fails. True works fine because it corresponds to 1
> which gives me the ascending sort. I guess a couple lines of code to
> handle my 1 to 2 to 1 toggle won't be too bad.
>
> Thanks
>
> Ken
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I control the sort order of a filter in a pivot table? Grizz Microsoft Excel Misc 1 20th Dec 2008 02:01 PM
boolean to control sort order Ken Microsoft Excel Programming 0 31st Oct 2008 02:41 PM
Start>Settings>Control Panel: Sort order =?Utf-8?B?TWlrZU1vbmV5?= Windows XP Customization 3 29th Aug 2006 06:37 AM
Start>Settings>Control Panel: Sort order =?Utf-8?B?TWlrZU1vbmV5?= Windows XP Setup 1 18th Aug 2006 07:10 PM
Sort order of combo box control =?Utf-8?B?S2V2aW4=?= Microsoft Access Forms 4 1st Feb 2006 06:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:29 AM.