#1   Report Post  
Mark1
 
Posts: n/a
Default VBA problem

Can anybody tell me why variable g is causing an error when it gets to
order1:=g? Why wouldn't d be causing the same error? Thanks!

d = InputBox("What cell do you want to sort by on this page?", Xpos:=9000,
Ypos:=7000)
g = InputBox("How do you want to sort? Please answer either" & Chr(13) & _
"with xlAscending or xlDescending", Xpos:=9000, Ypos:=7000)

If d = "" Then
GoTo Option1
End If

On Error GoTo Option2

ActiveSheet.Range(a, c).EntireRow.Select
Selection.Sort Key1:=Range(d), order1:=g
  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default

Because the sort order expects a long value of 1 or 2. xlAscending and
xlDescending are Excel constants that evaluate top 1 or 2. You cannot use a
string with xlAscending or xlDescending in the Sort function, you need to
decode to 1 or 2.

Maybe

Selection.Sort Key1:=Range(d), order1:=IIf(LCase(g) = "xlascending",
1, 2)

HTH

RP
(remove nothere from the email address if mailing direct)


"Mark1" wrote in message
...
Can anybody tell me why variable g is causing an error when it gets to
order1:=g? Why wouldn't d be causing the same error? Thanks!

d = InputBox("What cell do you want to sort by on this page?", Xpos:=9000,
Ypos:=7000)
g = InputBox("How do you want to sort? Please answer either" & Chr(13) &

_
"with xlAscending or xlDescending", Xpos:=9000, Ypos:=7000)

If d = "" Then
GoTo Option1
End If

On Error GoTo Option2

ActiveSheet.Range(a, c).EntireRow.Select
Selection.Sort Key1:=Range(d), order1:=g



  #3   Report Post  
Bernie Deitrick
 
Posts: n/a
Default

Mark1,

You aren't really using xlAscending and xlDescending, which are defined
constants. You are using strings instead, which aren't really the same
thing: "xlAscending" does not equal xlAscending

Instead, use soemthing like:

Dim g As Variant
g = MsgBox("Click Yes for Ascending and No for Descending", vbYesNo)

Then in the sort, use:

Order1:=IIf(g = vbYes, xlAscending, xlDescending)

HTH,
Bernie
MS Excel MVP

"Mark1" wrote in message
...
Can anybody tell me why variable g is causing an error when it gets to
order1:=g? Why wouldn't d be causing the same error? Thanks!

d = InputBox("What cell do you want to sort by on this page?", Xpos:=9000,
Ypos:=7000)
g = InputBox("How do you want to sort? Please answer either" & Chr(13) &

_
"with xlAscending or xlDescending", Xpos:=9000, Ypos:=7000)

If d = "" Then
GoTo Option1
End If

On Error GoTo Option2

ActiveSheet.Range(a, c).EntireRow.Select
Selection.Sort Key1:=Range(d), order1:=g



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
Row Autofit problem Excel 2003 Matthias Klaey Excel Discussion (Misc queries) 0 January 19th 05 05:33 PM
Baffling formula problem Ken Schmidt Excel Discussion (Misc queries) 2 December 21st 04 07:52 AM
Paper Tray selection Problem, Michael Hoffmann Excel Discussion (Misc queries) 4 December 3rd 04 09:08 PM
Custom Type Charts Problem Reetesh B. Chhatpar Excel Worksheet Functions 0 November 23rd 04 10:55 AM
label problem Raven Maniac Excel Worksheet Functions 5 November 10th 04 10:10 PM


All times are GMT +1. The time now is 04:45 PM.

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

About Us

"It's about Microsoft Excel"