Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
dd dd is offline
external usenet poster
 
Posts: 12
Default Using Macro to sort without clicking on macro button

Hi,
I have four columns of data. I want to sort Col C in ascending order,
then Col A in ascending order. When someone enters a name in Col C,
they would have to click on the macro button to resort the data. So
instead of clicking on the macro button, is there a way to
automatically resort the data after it is entered in Col C or Col A.
Thanks for your help.

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Using Macro to sort without clicking on macro button

You could use change event code in the worksheet but this negates the "undo"
feature so if you have made a mistake, your sort has taken place as soon as you
hit the ENTER button so makes it hard to troublesheet for errors in data entry.

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ws_exit:
If Intersect(Range(Target(1).Address), _
Range("A:A, C:C")) Is Nothing Then Exit Sub
Set OldCell = Target
Application.EnableEvents = False
Columns("C:C").Select
Selection.Sort Key1:=Range("C2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Columns("A:A").Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
OldCell.Select
ws_exit:
Application.EnableEvents = True
End Sub

This is sheet event code. Right-click on the sheet tab and "View Code".

Copy/paste into that sheet module.


Gord Dibben MS Excel MVP

On 2 May 2007 10:32:21 -0700, dd wrote:

Hi,
I have four columns of data. I want to sort Col C in ascending order,
then Col A in ascending order. When someone enters a name in Col C,
they would have to click on the macro button to resort the data. So
instead of clicking on the macro button, is there a way to
automatically resort the data after it is entered in Col C or Col A.
Thanks for your help.


  #3   Report Post  
Posted to microsoft.public.excel.misc
dd dd is offline
external usenet poster
 
Posts: 12
Default Using Macro to sort without clicking on macro button

Hi Gord,

Thanks for the quick reply but after I enter some text in Col C and
press enter key, nothing really happens, only Col C and Col D is
highlighted but none sorted.

I pasted the code in the sheet tab, view code.

The data actually begins on Row5 so I tried changing the A2 to A5 and
C2 to C5.

Any help is appreciated. Thanks again.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Using Macro to sort without clicking on macro button

I don't know what to say.

Works for me as written.

Sorts column C then Column A if data entered in column C or A and leaves the
active cell at last point of entry.

I would make one small change............

OldCell.Select becomes

OldCell.Offset(1, 0).Select would leave active cell at cell below last point of
data entry.

Did you copy/paste the code from my posting?


Gord


On 2 May 2007 16:41:39 -0700, dd wrote:

Hi Gord,

Thanks for the quick reply but after I enter some text in Col C and
press enter key, nothing really happens, only Col C and Col D is
highlighted but none sorted.

I pasted the code in the sheet tab, view code.

The data actually begins on Row5 so I tried changing the A2 to A5 and
C2 to C5.

Any help is appreciated. Thanks again.


Reply
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
Cannot see macro behind button? Kimberly Anne Excel Discussion (Misc queries) 1 August 31st 06 12:00 AM
use macro button to run macro in protected sheet earl Excel Discussion (Misc queries) 3 February 26th 06 10:21 PM
How do I use a macro button momma Excel Discussion (Misc queries) 2 February 5th 06 09:12 AM
F9 Button Macro Andrew McLeod Excel Discussion (Misc queries) 2 November 23rd 05 11:20 PM
Run macro from clicking on a cell jrd269 Excel Discussion (Misc queries) 2 June 3rd 05 09:35 PM


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

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"