Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default 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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default 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.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default 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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
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.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default 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.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default 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.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default 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.



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
using cell contents to link to other tabs CLGonline Excel Worksheet Functions 2 June 3rd 09 07:31 AM
Link format along with contents of another cell Claudia Excel Worksheet Functions 1 April 8th 09 07:24 PM
Macro to clear range contents when cell contents are changed by us Steve E Excel Programming 12 February 22nd 07 09:09 PM
All of contents in cell don't link CMIConnie Excel Discussion (Misc queries) 0 May 2nd 06 09:54 PM
Cell only shows link in text, not contents of reference cell Jay Mac New Users to Excel 4 August 23rd 05 08:36 PM


All times are GMT +1. The time now is 09:17 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"