Problem with VBA code not running in Excel 2003

S

Steve Muir

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
 
R

Ron Rosenfeld

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Applying Variables to SORT 4
Undo Macro Action 3
VBA 2 Codes 2
vba dynamic 1
Clear Check Box 2
Pictures not being sorted in VBA 2
Problem with Worksheet Activate and Sorting 7
Sorting Question 5

Top