LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Range object causing Sort to fail

Hello,

I'm trying to program in MSExcel 2003 a sort in a workbook that I
intend to lock down to prevent users from affecting the list box
validation source and the code keeps breaking at this line:
SrcRng.Sort Header:=xlYes, DataOption1:=xlSortNormal, Key1:=SKey1,
Order1:=Dir1

I can't figure this one out. Here is the full script:
Sub KCarSort()
Dim SKey1 As Range 'Sort Key 1
Dim SKey2 As Range 'Sort Key 2
Dim SKey3 As Range 'Sort Key 3
Dim Dir1 As String 'Sort Direction 1
Dim Dir2 As String 'Sort Direction 2
Dim Dir3 As String 'Sort Direction 3

Dim SrcRng As Range
Dim SrcHdrRng As Range

With ActiveWorkbook
MsgBox (Range(.Names("skey1")).Value)
Set SrcHdrRng = Range("A1:AL1")
Set SrcRng = Range("A1:AL1001")
If Range(.Names("Skey1")).Value < "" Then
Set SKey1 = SrcHdrRng.Find(what:=Range(.Names("Skey1")).Value)
If Range(.Names("Dir1")).Value < "" Then
Dir1 = "xl" & Range(.Names("dir1")).Value
Else
Dir1 = "xlAscending"
End If
Else: GoTo ENDING
End If

If Range(.Names("Skey2")).Value < "" Then
Set SKey2 = SrcHdrRng.Find(what:=Range(.Names("Skey2")).Value)
If Range(.Names("Dir2")).Value < "" Then
Dir2 = "xl" & Range(.Names("dir2")).Value
Else
Dir2 = "xlAscending"
End If
End If

If Range(.Names("Skey3")).Value < "" Then
Set SKey3 = SrcHdrRng.Find(what:=Range(.Names("Skey3")).Value)
If Range(.Names("Dir3")).Value < "" Then
Dir3 = "xl" & Range(.Names("dir3")).Value
Else
Dir3 = "xlAscending"
End If
End If


If Not SKey2 Is Nothing Then
If Not SKey3 Is Nothing Then
SrcRng.Sort Key1:=SKey1.Address, Order1:=Dir1 _
, Key2:=SKey2.Address, Order2:=Dir2 _
, Key3:=SKey3.Address, Order3:=Dir3
Else
SrcRng.Sort Key1:=SKey1.Address, Order1:=Dir1 _
, Key2:=SKey2.Address, Order2:=Dir2
End If
Else
SrcRng.Sort Header:=xlYes, DataOption1:=xlSortNormal, Key1:=SKey1,
Order1:=Dir1
End If
End With
ENDING: MsgBox ("You must select at least 1 criteria in the Sort 1
dropdown to perform a sort")
End Sub


Your assistance is greatly appreciated.


Steven
 
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
2003 works, 2007 doesn't: "Method 'Select' of object 'Shape' Fail MikeZz Excel Programming 2 November 8th 09 01:38 PM
error message Method €˜Add of object €˜CommandBar Controls fail? Sandy Pringle Excel Discussion (Misc queries) 2 October 30th 09 02:45 PM
Sort method of Range Object Failed Jim Cone Excel Programming 1 November 1st 05 10:49 PM
add-in macro strange errors--method sheets of object workbook fail DavidH[_2_] Excel Programming 3 November 4th 04 05:49 AM
method vbproject of object workbook fail Chrispy[_2_] Excel Programming 4 January 9th 04 06:56 AM


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

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"