Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Referring to the previous selected sheet in a macro | Excel Discussion (Misc queries) | |||
Create a report with selected rows based on the content in a cell | New Users to Excel | |||
group rows in a range based on criteria from another range (vba) | Excel Programming | |||
Referring to a user-selected range | Excel Programming | |||
Remove rows based on any selected criteria | Excel Programming |