View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson Jim Thomlinson is offline
external usenet poster
 
Posts: 5,939
Default 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.