LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.misc
 
Posts: n/a
Default numeric sort on one sheet, automatically sorts alphabetical on another?

Well now, isn't that cool!
I had a bit of trouble putting it into the sheet itself, the option to put
it there wasn't instinctive so I kept dropping it into a module. But I got
it in the right place now and it works as advertised.

Thanks a whole bunch.


"Leith Ross" wrote
in message ...

Hello,

Here is the automated version. Place this code inside the destination
worksheets' Worksheet_Activate() event. Change the variables SrcCell
(Starting cell on the source sheet), SourceSheet (to the name of the
source data worksheet) and DstCell (the starting cell of where the data
will be copied) to what match your layout. The macro automatically sizes
the source range, so you can add to it without changing addresses in the
macro code.


Code:
--------------------

Private Sub Worksheet_Activate()

Dim A, B
Dim DstCell As String
Dim DstCol As Long
Dim DstRng As Range
Dim I As Long
Dim FirstRow As Long
Dim LastRow
Dim SourceSheet As String
Dim SrcCell As String
Dim SrcCol As Long
Dim SrcRng As Range

'Variables for source and destination
SrcCell = "L10"
SourceSheet = "Sheet1"
DstCell = "D10"

'Find all data entries on the source worksheet
With Worksheets(SourceSheet)
SrcCol = .Range(SrcCell).Column
FirstRow = .Range(SrcCell).Row
LastRow = .Cells(Rows.Count, SrcCol).End(xlUp).Row
Set SrcRng = .Range(SrcCell, .Cells(LastRow, SrcCol + 1))
End With

With ActiveSheet
'Copy the data from the source sheet to the destination
DstCol = .Range(DstCell).Column
LastRow = (LastRow - FirstRow) + .Range(DstCell).Row
Set DstRng = .Range(DstCell, .Cells(LastRow, DstCol + 1))
DstRng() = SrcRng()
'Reverse the data
For I = 1 To DstRng.Cells.Count
A = DstRng.Cells(I, 1).Value
B = DstRng.Cells(I, 2).Value
DstRng.Cells(I, 1).Value = B
DstRng.Cells(I, 2).Value = A
Next I
'Sort the data from A to Z
DstRng.Sort Key1:=.Range(.Cells(1, DstCol), .Cells(LastRow, DstCol + 1))
End With

End Sub

--------------------


--
Leith Ross


------------------------------------------------------------------------
Leith Ross's Profile:
http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=497030



 
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
Using a relative SHEET reference for source data in a chart James Charts and Charting in Excel 6 August 16th 05 05:07 PM
How do I sort a list automatically? Defoes Right Boot Excel Discussion (Misc queries) 1 February 4th 05 05:56 PM
HELP! How do you--> Lock a set of rows but also link worksheets to FRUSTRATED Excel Discussion (Misc queries) 6 December 29th 04 10:05 PM
vba to sort group copy paste to another sheet mango Excel Worksheet Functions 0 November 5th 04 04:27 AM
sort automatically Mike Lemke Excel Worksheet Functions 2 October 31st 04 08:18 PM


All times are GMT +1. The time now is 03:19 PM.

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"