+ Reply to Thread
Results 1 to 6 of 6

call macro if cell is selected

  1. #1
    Corey
    Guest

    call macro if cell is selected

    Is it possible to have a macro run by clicking on a range or a single cell?

    Corey....



  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Corey,

    Yes you can. The drawback is the macro must be placed in the event code of each Worksheet where you want to use it.

    Here is the code. MyRange can be a single cell or range. Change this to want you want. Change MyMacro to the name of the macro you wish to execute.

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross
    Last edited by Leith Ross; 07-17-2006 at 12:22 AM.

  3. #3
    NickHK
    Guest

    Re: call macro if cell is selected

    Corey,
    Check out the SelectionChange event.
    You get new selected range in the Target argument.

    NickHK

    "Corey" <[email protected]> wrote in message
    news:uSG%[email protected]...
    > Is it possible to have a macro run by clicking on a range or a single

    cell?
    >
    > Corey....
    >
    >




  4. #4
    NickHK
    Guest

    Re: call macro if cell is selected

    Not necessarily, as there is the Workbook_SelectionChange.
    And if you use Application level events, a single routine for the whole of
    excel.
    http://www.cpearson.com/excel/AppEvent.htm

    NickHK

    "Leith Ross" <[email protected]> wrote
    in message news:[email protected]...
    >
    > Hello Corey,
    >
    > Yes you can. The drawback is the macro must be placed in the event code
    > of each Worksheet where you want to use it.
    >
    > Here is the code. MyRange can be a single cell or range. Change MyMacro
    > to the name of the macro you wish to execute.
    >
    >
    > Code:
    > --------------------
    >
    > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    > Dim MyRange As Range
    > Set MyRange = $A2:$E100
    > If Not Application.Intersect(Target, MyRange) Is Nothing Then Call

    MyMacro
    > End Sub
    >
    > --------------------
    >
    >
    > Sincerely,
    > Leith Ross
    >
    >
    > --
    > Leith Ross
    > ------------------------------------------------------------------------
    > Leith Ross's Profile:

    http://www.excelforum.com/member.php...o&userid=18465
    > View this thread: http://www.excelforum.com/showthread...hreadid=561911
    >




  5. #5
    Corey
    Guest

    Re: call macro if cell is selected

    Thanks guys,
    As the sheet i placed the code in was part of a copy and paste new sheet
    code, the code transfers to the other sheets also.
    I am using it to bring up a msg box to warn that a formula is contained in
    that cell selected. (Similar to protecting the cells)
    It works great.

    Regards

    Corey



  6. #6
    excelent
    Guest

    Re: call macro if cell is selected

    data validate - info is another way doing that



    "Corey" skrev:

    > Thanks guys,
    > As the sheet i placed the code in was part of a copy and paste new sheet
    > code, the code transfers to the other sheets also.
    > I am using it to bring up a msg box to warn that a formula is contained in
    > that cell selected. (Similar to protecting the cells)
    > It works great.
    >
    > Regards
    >
    > Corey
    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1