Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default Referring to a Range Based on Selected Rows

To sort a list such as the following alphanumerically, I've created
subroutines to insert a leading zero on the single-digit entries, sort, and
then strip off the leading zero. These work fine, assuming the user has
selected the entire range to be sorted, and not just entries in this column.

I'd like to bulletproof the macro by:
- determining the beginning and ending row of the selection (x, y)
- sorting the range Bx:Fy

Thanks for your input.

Sprinks

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Referring to a Range Based on Selected Rows

x = selection(1).row
y = selection(selection.count).row
set rng = Range(cells(x,"B"),cells(y,"F"))


--
Regards,
Tom Ogilvy


"Sprinks" wrote in message
...
To sort a list such as the following alphanumerically, I've created
subroutines to insert a leading zero on the single-digit entries, sort,

and
then strip off the leading zero. These work fine, assuming the user has
selected the entire range to be sorted, and not just entries in this

column.

I'd like to bulletproof the macro by:
- determining the beginning and ending row of the selection (x, y)
- sorting the range Bx:Fy

Thanks for your input.

Sprinks

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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default Referring to a Range Based on Selected Rows

Thanks, Tom; this works.

I'm having an additional problem. The Selection.Sort line in the following
code generates the error €œSort method of Range class failed.€

Can you tell me 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

Call RemoveLeadingZero

End Sub

Thank you.

"Sprinks" wrote:

To sort a list such as the following alphanumerically, I've created
subroutines to insert a leading zero on the single-digit entries, sort, and
then strip off the leading zero. These work fine, assuming the user has
selected the entire range to be sorted, and not just entries in this column.

I'd like to bulletproof the macro by:
- determining the beginning and ending row of the selection (x, y)
- sorting the range Bx:Fy

Thanks for your input.

Sprinks

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

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
Referring to the previous selected sheet in a macro michaelberrier Excel Discussion (Misc queries) 2 June 12th 06 01:35 PM
Create a report with selected rows based on the content in a cell ThirdTim New Users to Excel 1 May 5th 05 05:18 PM
group rows in a range based on criteria from another range (vba) Andy Excel Programming 2 April 28th 04 03:26 AM
Referring to a user-selected range James Mc Excel Programming 2 January 27th 04 07:46 AM
Remove rows based on any selected criteria Juan[_2_] Excel Programming 0 September 25th 03 06:13 PM


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