LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default Sort Error

Thanks, Jim, it works flawlessly now.

Sprinks

"Jim Thomlinson" wrote:

A couple of things. you don't need the select. Since you have a range object
you can just sort it, but you have to specify a key. My guess would be by the
cell intfirst and column B, but that is up to you. Record a macro to see all
of the possible properties that you can set. Heading will probably be xlYes
and there may be a few other things you want to set.

rng.sort Key1:=???, ...
--
HTH...

Jim Thomlinson


"Sprinks" wrote:

The following code is designed to sort an alphanumeric list consisting of
text & one or 2 digits by inserting a leading zero, sorting, and then
stripping the zero back, to produce the following results:

Pre-sort condition
--------------------
AC20
AC1
AC2
AC9
AC10

Normal Excel Sort Result
-----------------------------
AC1
AC10
AC2
AC20
AC9

Macro Sort Result
---------------------
AC1
AC2
AC9
AC10
AC20

The Selection.Sort line in the following code generates the error €œSort
method of Range class failed.€

Does anyone know why?

Sub AlphaSort()
Dim rng As Range
Dim intFirst As Integer
Dim intLast As Integer

' Sorts Alphanumeric list by adding then removing leading zeros
Call AddLeadingZero

intFirst = Selection(1).Row
intLast = Selection(Selection.Count).Row
Set rng = Range(Cells(intFirst, "B"), Cells(intLast, "F"))
rng.Select

Selection.Sort 'Code fails here

Call RemoveLeadingZero

End Sub

Thank you.
Sprinks

 
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
TABLE ROW SORT ERROR? RAY Excel Discussion (Misc queries) 1 May 6th 10 08:20 PM
vlookup and sort error LiveUser Excel Worksheet Functions 2 November 7th 07 03:41 PM
Sort error jpas1954 Excel Discussion (Misc queries) 1 January 24th 07 04:24 PM
sort ascending error blefevre Excel Discussion (Misc queries) 2 August 20th 06 04:42 PM
Selection.Sort error Krager Excel Programming 3 September 3rd 05 06:12 PM


All times are GMT +1. The time now is 08:55 AM.

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"