ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sorting Range Help (https://www.excelbanter.com/excel-programming/286992-sorting-range-help.html)

HelpMe

Sorting Range Help
 
I Have a problem i am not sure how to solve. I have created a Sort
option seen below my problem is that i do not want to always stop in
N24. Is there a way to solve this? Thanks in advance.

Sub Sorty()

Range("A12:N24").Select
Selection.Sort Key1:=Range("D12"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("A12:B12").Select
Selection.AutoFill Destination:=Range("A12:B23"),
Type:=xlFillDefault
Range("A12:B23").Select
End Sub


---
Message posted from http://www.ExcelForum.com/


Nick Hodge

Sorting Range Help
 
There is seldom any need for all the 'Select' you have as you can operate on
the range without selecting, but to simply cure your issue modify the code
as shown

Sub Sorty()
Dim lLastRow as Long
lLastRow=Range("N65536").End(xlUp).Row
Range("A12:"&lLastRow).Select
Selection.Sort Key1:=Range("D12"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("A12:B12").Select
Selection.AutoFill Destination:=Range("A12:B23"),
Type:=xlFillDefault
Range("A12:B23").Select
End Sub


--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS


"HelpMe " wrote in message
...
I Have a problem i am not sure how to solve. I have created a Sort
option seen below my problem is that i do not want to always stop in
N24. Is there a way to solve this? Thanks in advance.

Sub Sorty()

Range("A12:N24").Select
Selection.Sort Key1:=Range("D12"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("A12:B12").Select
Selection.AutoFill Destination:=Range("A12:B23"),
Type:=xlFillDefault
Range("A12:B23").Select
End Sub


---
Message posted from
http://www.ExcelForum.com/




HelpMe

Sorting Range Help
 
Thanks for the help but I am getting an error and not sure how to solv
it!:confused: It Says *Method 'Range' of object '_Global' failed*
Here is the code I am using.

Sub Sorty()
Dim lLastRow As Long
lLastRow = Range("M65536").End(xlUp).Row
Range("B12:" & lLastRow).Select
Selection.Sort Key1:=Range("D12"), Order1:=xlAscending
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub

Thanks for any help

--
Message posted from http://www.ExcelForum.com


Chip Pearson

Sorting Range Help
 
The line of code
Range("B12:" & lLastRow).Select
should be
Range("B12:M" & lLastRow).Select


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"HelpMe " wrote in message
...
Thanks for the help but I am getting an error and not sure how

to solve
it!:confused: It Says *Method 'Range' of object '_Global'

failed*.
Here is the code I am using.

Sub Sorty()
Dim lLastRow As Long
lLastRow = Range("M65536").End(xlUp).Row
Range("B12:" & lLastRow).Select
Selection.Sort Key1:=Range("D12"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub

Thanks for any help!


---
Message posted from http://www.ExcelForum.com/




Nick Hodge

Sorting Range Help
 
Oops

That's what comes of trying to be clever and not testing...sorry! Thanks
for bailing me out Chip ;-)

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS


"Chip Pearson" wrote in message
...
The line of code
Range("B12:" & lLastRow).Select
should be
Range("B12:M" & lLastRow).Select


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"HelpMe " wrote in message
...
Thanks for the help but I am getting an error and not sure how

to solve
it!:confused: It Says *Method 'Range' of object '_Global'

failed*.
Here is the code I am using.

Sub Sorty()
Dim lLastRow As Long
lLastRow = Range("M65536").End(xlUp).Row
Range("B12:" & lLastRow).Select
Selection.Sort Key1:=Range("D12"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub

Thanks for any help!


---
Message posted from http://www.ExcelForum.com/







All times are GMT +1. The time now is 07:12 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com