![]() |
Link cell contents to a Macro?
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. |
Link cell contents to a Macro?
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. |
Link cell contents to a Macro?
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. |
Link cell contents to a Macro?
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. |
Link cell contents to a Macro?
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. |
Link cell contents to a Macro?
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. |
Link cell contents to a Macro?
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. |
All times are GMT +1. The time now is 06:48 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com