LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.misc
Toppers
 
Posts: n/a
Default how do I automatically sort a column on entry

Michael,
Put your sort code into a separate module (as per your
original macro) and call it from the w/sheet change module as shown below.


Sub mysort()
Sheets("standings").Activate ' <====(go to the standngs sheet)
Range("B1").Select
Range("A1:B8").sort Key1:=Range("B2"), Order1:=xlDescending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Sheets("results").Selec
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
Dim isectrng As Range

On Error GoTo Wsexit
Application.EnableEvents = False
Application.ScreenUpdating = False

Set isectrng = Range("e:f") ' <===== (the range where the data entry
occurs)
Set isect = Application.Intersect(Target, isectrng)
If isect Is Nothing Then
Else
Call mysort ' Call sort routine
End If

Wsexit:
Application.EnableEvents = True
End Sub

"Michael" wrote:

Hi, that's great, thank you very much.
However, because I enter the data on a different sheet (results) it doesn't
work unless I change something on the sheet with the table (Standings). I
have tried pasting the formula on the input sheet and amending the formula as
below but it isn't working. Any ideas?

NB this module is on the results sheet (where I do the entry) and the table
is on the standings sheet

Private Sub Worksheet_Change(ByVal Target As Range)
Dim isectrng As Range

On Error GoTo Wsexit
Application.EnableEvents = False
Application.ScreenUpdating = False

Set isectrng = Range("e:f") <===== (the range where the data entry occurs)
Set isect = Application.Intersect(Target, isectrng)
If isect Is Nothing Then
Else
Sheets("standings").Select <====(go to the standngs sheet)
Range("B1").Select
Range("A1:B8").Sort Key1:=Range("B2"), Order1:=xlDescending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Sheets("results").Select <====(go back to the results sheet)
End If

Wsexit:
Application.EnableEvents = True
End Sub



"Toppers" wrote:

This example checks if changes has occurred in columns L & N and if yes, call
the routine SortTable.

You can add your sort macro code tto replace the SortTtable

Right click on the w/sheet tab, "view code" and copy/paste the code below;
modify as required.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim isectrng As Range

On Error GoTo Wsexit
Application.EnableEvents = False
Application.ScreenUpdating = False

Set isectrng = Range("L:L,N:N")
Set isect = Application.Intersect(Target, isectrng)
If isect Is Nothing Then
Else
SortTable '<=== insert you code here and remove this line
End If

Wsexit:
Application.EnableEvents = True
End Sub

HTH

"Michael" wrote:

Thanks, what worksheet event do I use and how do I action it?
I have recorded the sort macro but don't understand how to make it work when
I enter an item. In fact the best way to action the sort is when the relevant
worksheet is opened. Does it need to be pasted onto the worksheet code and if
so what would be the extra line I need to add to the macro to make it run on
selecting that worksheet?
Thanks for your time.

"Toppers" wrote:

You will need a worksheet event to invoke the sort when selected columns are
updated. Record the desired sort as a macro and insert this code in the
worksheet event code.

See the Chip Pearson's site below for more on events:

http://www.cpearson.com/excel/events.htm

"Michael" wrote:

Hi, I have a spreadsheet with a number of entries over 25 columns on sheet1
that are totalled in row 30 (cells A30 to Y30). On sheet2 I have a summary
for each category that is linked to the sums on sheet1. I would like the
sheet2 summary to automatically sort every time I update the numbers on
sheet1. Could anyone help please.
Thanks.

 
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
How do I sort by row instead of by column? PercivalMound Excel Worksheet Functions 7 August 28th 06 10:41 PM
prevent column from being included in sort in Excel jannkatt Excel Discussion (Misc queries) 0 June 12th 06 01:46 PM
Return SEARCHED Column Number of Numeric Label and Value Sam via OfficeKB.com Excel Worksheet Functions 23 January 30th 06 06:16 PM
How do I sort a column of formulas in Excel? Gordon Excel Discussion (Misc queries) 2 November 27th 04 01:55 AM
How do I sort a column of formulas in Excel? Gordon Excel Discussion (Misc queries) 0 November 26th 04 03:19 PM


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