Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'd like to call a macro that sorts a list simply by clicking on a header cell.
Sort Key1 = the cell that the user clicks on. Can one call a macro by clicking on a cell or the contents of a cell? If so, how? Thanks very much. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Yes, Right-Click the sheet in question. Select "View Code". Use this
event: Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Address < Range("A1").Address Then 'Change A1 for your Cell Exit Sub End If 'Your Code to sort End Sub HTH Charles Chickering Dave wrote: I'd like to call a macro that sorts a list simply by clicking on a header cell. Sort Key1 = the cell that the user clicks on. Can one call a macro by clicking on a cell or the contents of a cell? If so, how? Thanks very much. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
This can be accomplished by using a Worksheet_SelectionChange macro. This
macro will run whenever a given cell is selected. If you are not familiar with even macros, see: http://cpearson.com/excel/events.htm -- Gary's Student "Dave" wrote: I'd like to call a macro that sorts a list simply by clicking on a header cell. Sort Key1 = the cell that the user clicks on. Can one call a macro by clicking on a cell or the contents of a cell? If so, how? Thanks very much. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You could try something like this. This code is placed in the sheet and not
in a module where recorded macro's are. Right click the sheet tab in Excel and select View Code. Paste the following: Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Not Intersect(Target, Range("B1:E1")) Is Nothing Then Range("A1:E100").Sort Key1:=Target, Order1:=xlAscending, Header:=xlYes End If End Sub When a cell B1:E1 is selected it sorts the range A1:E100 -- HTH... Jim Thomlinson "Dave" wrote: I'd like to call a macro that sorts a list simply by clicking on a header cell. Sort Key1 = the cell that the user clicks on. Can one call a macro by clicking on a cell or the contents of a cell? If so, how? Thanks very much. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thank you very much. This works well.
"Jim Thomlinson" wrote: You could try something like this. This code is placed in the sheet and not in a module where recorded macro's are. Right click the sheet tab in Excel and select View Code. Paste the following: Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Not Intersect(Target, Range("B1:E1")) Is Nothing Then Range("A1:E100").Sort Key1:=Target, Order1:=xlAscending, Header:=xlYes End If End Sub When a cell B1:E1 is selected it sorts the range A1:E100 -- HTH... Jim Thomlinson "Dave" wrote: I'd like to call a macro that sorts a list simply by clicking on a header cell. Sort Key1 = the cell that the user clicks on. Can one call a macro by clicking on a cell or the contents of a cell? If so, how? Thanks very much. |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thank you for the link. It was very helpful.
"Gary''s Student" wrote: This can be accomplished by using a Worksheet_SelectionChange macro. This macro will run whenever a given cell is selected. If you are not familiar with even macros, see: http://cpearson.com/excel/events.htm -- Gary's Student "Dave" wrote: I'd like to call a macro that sorts a list simply by clicking on a header cell. Sort Key1 = the cell that the user clicks on. Can one call a macro by clicking on a cell or the contents of a cell? If so, how? Thanks very much. |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks for the tip. Very helpful.
"Die_Another_Day" wrote: Yes, Right-Click the sheet in question. Select "View Code". Use this event: Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Address < Range("A1").Address Then 'Change A1 for your Cell Exit Sub End If 'Your Code to sort End Sub HTH Charles Chickering Dave wrote: I'd like to call a macro that sorts a list simply by clicking on a header cell. Sort Key1 = the cell that the user clicks on. Can one call a macro by clicking on a cell or the contents of a cell? If so, how? Thanks very much. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
using cell contents to link to other tabs | Excel Worksheet Functions | |||
Link format along with contents of another cell | Excel Worksheet Functions | |||
Macro to clear range contents when cell contents are changed by us | Excel Programming | |||
All of contents in cell don't link | Excel Discussion (Misc queries) | |||
Cell only shows link in text, not contents of reference cell | New Users to Excel |