+ Reply to Thread
Results 1 to 11 of 11

Automatically clear contents of cell when selected

  1. #1
    Registered User
    Join Date
    11-22-2008
    Location
    house
    Posts
    68

    Automatically clear contents of cell when selected

    Hi there,

    Is there way to automatically clear the contents of a cell when the user clicks in that cell. Eg, click in "A1" then then "A1" clears automatically.

    Thanks
    Last edited by staples; 10-15-2009 at 03:48 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Automatically clear contents of cell when selected

    Try this, note it will work on all cells so you will probably need to amend it to be more practical
    Please Login or Register  to view this content.
    Copy the code
    Select the worksheet in which you the code to run
    Right click on the sheet tab and choose View Code, to open the Visual Basic Editor.
    Where the cursor is flashing, choose Edit | Paste
    Last edited by royUK; 10-13-2009 at 09:11 AM.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    11-22-2008
    Location
    house
    Posts
    68

    Re: Automatically clear contents of cell when selected

    hi there,

    thanks for the reply and suggestion. however, the problem i was having is acutally getting to work for just one cell when it is selected, i am not sure how to do this.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Automatically clear contents of cell when selected

    Is this what you mean? The code will only run if A1 is selected
    Please Login or Register  to view this content.
    Last edited by royUK; 10-14-2009 at 07:31 AM.

  5. #5
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    Re: Automatically clear contents of cell when selected

    My two cents.
    I would make it a DoubleClick event.
    The problem with deleting something with VBA is that you can't undo it, without some more VBA programming.
    The DoubleClick would avoid frustration.

    Better yet, I have created a confrimation message window in some of my applications, to give the user a second chance, in case they make a mistake.

    modytrane

  6. #6
    Registered User
    Join Date
    11-22-2008
    Location
    house
    Posts
    68

    Re: Automatically clear contents of cell when selected

    hi there,

    thanks for the code but i cant actually get it to do anything....? I pasted it into the worksheet (sheet1) code area. Is this correct?

    I think you understand what I was after though yes. I have a value in A1 which links into the autofilter and will filter out the rest of the worksheet based on the entry in A1. At which point the user can scroll around the sheet as usual.

    What I would like is that, when the user clicks into A1 again ready to enter a new value the current cell would automatically clear and be blank, which in turn then filters out all data.

    i hope this makes sence

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Automatically clear contents of cell when selected

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!

  8. #8
    Registered User
    Join Date
    11-22-2008
    Location
    house
    Posts
    68

    Re: Automatically clear contents of cell when selected

    Hi again

    Please find the spreadsheet attached below:

    When the sheet is first opened, the selections are completely blank, and therefore the filters so no data, which I how I want it. A user will enter a code into B3, eg 2001 or 2004 then the data for the code will display. Then, what I would like, if possible, is that when the user clicks into B3 again, ready to enter a new code, the previous code will be cleared and therefore the entire sheet will be blank again, like when it was first opened.

    I hope this clears up and confusion

    Thanks again
    Attached Files Attached Files

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Automatically clear contents of cell when selected

    For a start you cannot have two events for the same object, you are trying to use the selection_change event twice

    You have merged Cells B3 to C3, this will cause problems, merged cells should really be avoided. In this case centre across selection from he Format -> Cells menu options is ok.

    If you remove the merged cells as above then this code should work
    Please Login or Register  to view this content.

  10. #10
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Automatically clear contents of cell when selected

    It will also be tidier if you replace the formula in E2, = P3, with =IF(ISERROR(P3),"",P3)

  11. #11
    Registered User
    Join Date
    11-22-2008
    Location
    house
    Posts
    68

    Re: Automatically clear contents of cell when selected

    hi there,

    thanks for your help, its working well!

+ 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