+ Reply to Thread
Results 1 to 4 of 4

run macro upon clicking a cell?

  1. #1
    Registered User
    Join Date
    08-19-2006
    Posts
    2

    run macro upon clicking a cell?

    I wrote a little macro (module, general) and at the moment it's running on pressing ctr+q.

    Now I wonder if it's possible to make it run everytime i click a cell.

    Or if not so, then if it's possible to make it run like every 2 seconds.

    Please note that this is my first excel macro, so i don't really know anything about macroes yet,

    thx in advance,

    the blue rider

  2. #2
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    Paste this in to the worksheet code module. Every time you click a cell on the worksheet it will call your macro

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Call YOUR MACRO NAME HERE
    End Sub

    Regards,
    Simon

  3. #3
    Bob Phillips
    Guest

    Re: run macro upon clicking a cell?

    On selecting a cell

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Const WS_RANGE As String = "A1:H10"

    If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
    With Target
    'do your stuff
    End With
    End If

    End Sub

    'This is worksheet event code, which means that it needs to be
    'placed in the appropriate worksheet code module, not a standard
    'code module. To do this, right-click on the sheet tab, select
    'the View Code option from the menu, and paste the code in.



    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "thebluerider" <[email protected]>
    wrote in message
    news:[email protected]...
    >
    > I wrote a little macro (module, general) and at the moment it's running
    > on pressing ctr+q.
    >
    > Now I wonder if it's possible to make it run everytime i click a cell.
    >
    > Or if not so, then if it's possible to make it run like every 2
    > seconds.
    >
    > Please note that this is my first excel macro, so i don't really know
    > anything about macroes yet,
    >
    > thx in advance,
    >
    > the blue rider
    >
    >
    > --
    > thebluerider
    > ------------------------------------------------------------------------
    > thebluerider's Profile:

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




  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,485
    This could work, right click on the worksheets tab
    select view codes
    in the code window select worksheet from the drop down, in the dropdown to the right select SelectionChange

    place you macro code in the sub, when ever you change the selection on the sheet the macro will kick in.
    Use the code below as an example:

    MsgBox "Macro goes here"




    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    MsgBox "Macro goes here"

    End Sub

+ 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