Tuesday, July 23, 2013

How to Assign a Macro to a Cell in Excel


1. Right-click the sheet tab you want the change to happen in. The sheet tabs are at the very bottom of the worksheet.
2. Click 'View Code.'
3. Cut and post the following code into the worksheet:Private Sub Worksheet_SelectionChange(ByVal Target As Range)If Target.Address = '$A$1' ThenRange('A10') = 'Your text here'End IfEnd Sub
4. Change the code to suit your needs. The above code writes 'Your text here' into cell 'A10' when cell 'A1' is clicked. Change the 'A1' in 'Target.Address = '$A$1'' to the cell you want to click, then change Range('A10') = 'Your text here' to indicate the cell you want the event to happen in and the text you want to appear.

Blogger news