Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Problem with VBA code not running in Excel 2003

Hi All,

I have recently developed a sheet which checks the distance between 2
postcodes and then outputs results to another sheet and sorts them by
distance (closest to furthest).

This works perfectly in Excel 2007 (which I developed the sheet with) but
when my collegue runs it in 2003 the code for the sort fails. The code is:

Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Worksheets("Agencies by Distance").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Agencies by Distance").Sort.SortFields.Add
Key:=Range("F7"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Agencies by Distance").Sort
.SetRange Range("A7:H1000")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

It fails on the second line of code and I don't know why? Can anyone shed
any light on this for me.

many thanks

Stephen Muir
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problem with VBA code not running in Excel 2003


The code is using the sort GUI from the worksheet which may be set to
different settings. try this simplier code. You code wasn't reffering
to the active worksheet when determining the last row which probably
gave the error.


with ActiveWorkbook.Worksheets("Agencies by Distance")
Set LastRow = .Range("A7").End(xldown).Row
Set sortRange = .Range("A7:H" & Lastrow)

SortRange.Sort _
Header:=Xlno
key1:=.Range("F7"),
Order1:=xlascending
end with


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=183784

Microsoft Office Help

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Problem with VBA code not running in Excel 2003

On Tue, 2 Mar 2010 03:47:01 -0800, Steve Muir
wrote:

Hi All,

I have recently developed a sheet which checks the distance between 2
postcodes and then outputs results to another sheet and sorts them by
distance (closest to furthest).

This works perfectly in Excel 2007 (which I developed the sheet with) but
when my collegue runs it in 2003 the code for the sort fails. The code is:

Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Worksheets("Agencies by Distance").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Agencies by Distance").Sort.SortFields.Add
Key:=Range("F7"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Agencies by Distance").Sort
.SetRange Range("A7:H1000")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

It fails on the second line of code and I don't know why? Can anyone shed
any light on this for me.

many thanks

Stephen Muir



Well, for one thing, I don't believe the SortMethod member was present prior to
XL2007. Since it's used for Chinese languages according to HELP, you might be
able to omit it. If not, perhaps someone has a workaround to use in XL2003.
--ron
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
problem running code DDD Excel Programming 9 January 27th 09 06:58 AM
Problem running VBA 2000 code in Excel 2003 Smurfette18 Excel Programming 3 December 14th 07 09:34 PM
XL 2003: Problem running Solver from VBA Robert Valentine Excel Programming 1 December 22nd 06 03:00 PM
Problem Running Code in Excel 2003 Mark Excel Programming 1 June 17th 05 12:45 AM
Problem running code behind a userform cdb Excel Programming 17 February 10th 05 03:53 PM


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