ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sorting based on a cell (https://www.excelbanter.com/excel-programming/312497-sorting-based-cell.html)

scottwilsonx[_50_]

Sorting based on a cell
 

Thanks to Tom who replied to my earlier email.
I have made some alterations, which are detailed below:

Data range from B5 to Z37 where row 5 is the header showing Apr-03 t
Mar-05 in C5 to Z5. and where column B contains the row headers.

My sort macro looks like this:

Sub SORT()
Dim SortMonth As Integer
Range("B2").Value = SortMonth
Range("B5:Z37").Select
Selection.SORT Key1:=Range(SortMonth), Order1:=xlAscending
End Sub

It isn't working properly. I have created a SortMonth dimension whic
is based on the value in cell B2. What I would like to do is where th
Selection.Sort looks for a range, I want it to look in B2 and take tha
value, which is equivalent to the months in C5 to Z5.

Thanks for your help.

Regards

Scott

--
scottwilson
-----------------------------------------------------------------------
scottwilsonx's Profile: http://www.excelforum.com/member.php...fo&userid=1112
View this thread: http://www.excelforum.com/showthread.php?threadid=26638


Jim May

Sorting based on a cell
 
Try changing line:
Range("B2").Value = SortMonth

to:
SortMonth = Range("B2").Value


"scottwilsonx" wrote in message
...

Thanks to Tom who replied to my earlier email.
I have made some alterations, which are detailed below:

Data range from B5 to Z37 where row 5 is the header showing Apr-03 to
Mar-05 in C5 to Z5. and where column B contains the row headers.

My sort macro looks like this:

Sub SORT()
Dim SortMonth As Integer
Range("B2").Value = SortMonth
Range("B5:Z37").Select
Selection.SORT Key1:=Range(SortMonth), Order1:=xlAscending
End Sub

It isn't working properly. I have created a SortMonth dimension which
is based on the value in cell B2. What I would like to do is where the
Selection.Sort looks for a range, I want it to look in B2 and take that
value, which is equivalent to the months in C5 to Z5.

Thanks for your help.

Regards

Scott.


--
scottwilsonx
------------------------------------------------------------------------
scottwilsonx's Profile:

http://www.excelforum.com/member.php...o&userid=11128
View this thread: http://www.excelforum.com/showthread...hreadid=266388





All times are GMT +1. The time now is 05:40 PM.

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