Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Assigning Macro to a cell

How can I get a macro to run by clicking in a cell.

I have numerous columns of data. When I click in the column title in row 4,
I then want the data in rows 6 to 314 in that same column to be copied to
column D. (From there it feeds through to a report sheet). I have created
the VB for the copying and it runs fine whenever a cell in row 4 is
selected. But I cannot get it to run on its own simply by selecting the
cell.

How is this done please?

Thank you in advance

Peter


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Assigning Macro to a cell

In the Sheet code module for the appropriate sheet, use the
SelectionChange event procedure. This will execute whenever you
select a cell.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Row = 4 Then
' your code here
End If
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Peter" wrote in message
...
How can I get a macro to run by clicking in a cell.

I have numerous columns of data. When I click in the column
title in row 4,
I then want the data in rows 6 to 314 in that same column to be
copied to
column D. (From there it feeds through to a report sheet). I
have created
the VB for the copying and it runs fine whenever a cell in row
4 is
selected. But I cannot get it to run on its own simply by
selecting the
cell.

How is this done please?

Thank you in advance

Peter




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Assigning Macro to a cell


Suppose you have MyMacro typed in Range("C1"). To run MyMacro by clicking in
the cell C1, place this code in the ThisWorkbook module:


Public Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As
Range)

Dim sMacro As String

If Not Application.Intersect(Range("C1"), ActiveCell) Is Nothing Then
If Application.ScreenUpdating = True Then
sMacro = Range(Target.Address).Value
Application.Run sMacro
End If
End If

End Sub




Peter wrote:
How can I get a macro to run by clicking in a cell.

I have numerous columns of data. When I click in the column title in row 4,
I then want the data in rows 6 to 314 in that same column to be copied to
column D. (From there it feeds through to a report sheet). I have created
the VB for the copying and it runs fine whenever a cell in row 4 is
selected. But I cannot get it to run on its own simply by selecting the
cell.

How is this done please?

Thank you in advance

Peter

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
assigning value in macro tina Excel Programming 4 October 29th 09 03:33 PM
assigning macro carrera Excel Discussion (Misc queries) 16 March 21st 08 09:00 PM
Assigning macro to button d Excel Discussion (Misc queries) 0 August 22nd 05 01:40 PM
assigning macro to cell Adam Excel Programming 6 April 22nd 05 05:19 PM
Macro assigning help PLEASE Jim Rech Excel Programming 0 February 10th 04 10:03 PM


All times are GMT +1. The time now is 07:52 PM.

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"