+ Reply to Thread
Results 1 to 4 of 4

Programming Excel to change colour of cells when clicked

  1. #1
    Registered User
    Join Date
    11-02-2007
    Posts
    2

    Programming Excel to change colour of cells when clicked

    Hey all,

    Can anyone tell me how to program a cell (actually a range of cells 20x20), so that when I click on one of the cells in that range, the cell I click on changes colour? Ideally if I click on it again, it should change to a second colour, then a third colour, and a fourth click will see it return to its original state of no colour.

    Thanks heaps, much appreciated.

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Excel does not have an Onclick Macro function
    It dose have a :-
    Worksheet_SelectionChange
    Worksheet_BeforeDoubleClick
    Worksheet_BeforeRightClick

    I have used Worksheet_SelectionChange triggered macro (the code can be used in the other macro types mentiond

    This macro wil run whenever a cell is selected.
    The downside to it is if a cell is already selected you can not click on the cell a 2nd time - you need to select a different cell 1st. It will also run if you move the curser by using the arrow keys.


    'These instructions pre typed & are worded to cater for the novice programmer
    'To install macro to correct location

    'Copy this macro
    'GoTo Excel
    'Select sheet this is to appy to
    'Right Click on Sheet Name Tab > select View Code
    'Past macro into the Worksheet Module displayed

    Please Login or Register  to view this content.
    You can even use a combiation of 2 types
    This macro calls the Worksheet_SelectionChange macro if a cell is double clicked
    Please Login or Register  to view this content.
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  3. #3
    Registered User
    Join Date
    11-02-2007
    Posts
    2

    Smile

    hey man, that's perfect! I adjusted the area which i am targeting and selcted different colours, so the macro now looks like this:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

    As you can see, I used the combination you suggested for the double click - perfect. Thanks heaps.
    Last edited by VBA Noob; 11-05-2007 at 03:30 AM.

  4. #4
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Please read forum rules & wrap your VBA code

    A thread with the rules is available at the top of each forum or see links below

    If you do not understand the VBA code wrap instructions have a look at my last reply in this thread
    http://www.excelforum.com/showthread.php?t=583950

+ 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