+ Reply to Thread
Results 1 to 19 of 19

Clear cell when another changes

  1. #1
    Registered User
    Join Date
    02-15-2011
    Location
    Merseyside
    MS-Off Ver
    Excel 2011 For Mac
    Posts
    11

    Clear cell when another changes

    Hi,

    I have never used VB before and have no real understanding of it, but I believe I need it to solve my problem.

    Column E has a drop down list in every cell. Column F then has drop down list dependent on what you select in column E.

    I would like to be able to have the cell in column F clear if column E is changed.
    ie Change cell E8, then F8 will clear,

    this would happen for all the cells from E6:E505

    Hope that makes sense.

    Any help in baby steps and language would be really appreciated.

    Thank so much

    C

  2. #2
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Clear cell when another changes

    VB can do this for you.
    1. Open your workbook
    2. Hit Alt+F11
    3. Hit Ctrl+R to open the Project Explorer
    4. In the project explorer on the left, double click the Sheet Name where you are working
    5. Copy the code below
    6. Paste the code on the white page that opened in Excel
    7. Close that Window

    Please Login or Register  to view this content.

    You are done. Whenever something in E5:E505 changes, the cell to the right of it will clear itself.

    As for the code itself:
    The first line is the name of the subroutine and it's type (Worksheet_Change) and what the parameters of that are (the targeted range).
    The second line says "if someone selects anything that's not E5:E505, or if they select many cells, don't run this VB"
    The third lines says for a given cell that passed the first statement, clear the cell to the right of it.
    Last edited by daffodil11; 09-29-2014 at 06:59 PM.
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  3. #3
    Registered User
    Join Date
    02-15-2011
    Location
    Merseyside
    MS-Off Ver
    Excel 2011 For Mac
    Posts
    11

    Re: Clear cell when another changes

    Thanks so much for your reply.

    I'm using Excel for Mac 2011 so went into the developer tab, clicked on editor, discovered there are 2 folders both identical called VBA project. I clicked on the worksheet I wanted, pasted the code, clicked the save icon, closed it all and tried the worksheet. Nothing happens.

    Went back in and pasted the code into the identical worksheet bit under the other VBA project folder. Still nothing works.

    No idea what I'm doing wrong!

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Clear cell when another changes

    Quote Originally Posted by richardson.cr View Post
    pasted the code into the identical worksheet bit under the other VBA project folder. Still nothing works.
    Remove the codes.

    SheetEvent codes can be easily applied by doing right click on the concerned sheet and select view code and paste it.

    Close the VBA window (Alt+Q to close VBA window) and return to that sheet and check


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  5. #5
    Registered User
    Join Date
    02-15-2011
    Location
    Merseyside
    MS-Off Ver
    Excel 2011 For Mac
    Posts
    11

    Re: Clear cell when another changes

    Thanks, but that definitely doesn't work. I deleted the code as you said, but when I right click on the worksheet or the worksheet tab there is no option to view code.

    I tried googling it and it says for Excel on a Mac you have to go to Tools>Macro>Visual Basic Editor which simply takes me back to the same place I've just been to delete the code.

  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Clear cell when another changes

    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  7. #7
    Registered User
    Join Date
    02-15-2011
    Location
    Merseyside
    MS-Off Ver
    Excel 2011 For Mac
    Posts
    11

    Re: Clear cell when another changes

    OK, I've done this basic one to show what I need.

    Basically I have two drop down lists (2nd one is dependent on 1st). I simply want it so if somebody changes their selection in the first column, it clears their previous selection in the second column.

    I want this to apply all the way down the column so if they change a selection on any row in column E, it will clear the selection on the same row in column F.

    (Obviously in my example sheet i've just put the boxes in A and B and only on one row).
    Attached Files Attached Files

  8. #8
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Clear cell when another changes

    Please check the attached file and confirm

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

  9. #9
    Registered User
    Join Date
    02-15-2011
    Location
    Merseyside
    MS-Off Ver
    Excel 2011 For Mac
    Posts
    11

    Re: Clear cell when another changes

    Thanks for your quick responses, I clicked on your file and said enable macros.

    I then selected "Veg" in the first column and "Red" in the 2nd. When I go back and change veg to fruit, the Red remains there and doesn't clear. Does this mean maybe something isn't activated on my version of Excel which is why none of these things are working?

  10. #10
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Clear cell when another changes

    In VBA window press Ctrl+G and enter this below line and press enter

    Please Login or Register  to view this content.
    Please confirm what result you get after entering that line in immediate window

  11. #11
    Registered User
    Join Date
    02-15-2011
    Location
    Merseyside
    MS-Off Ver
    Excel 2011 For Mac
    Posts
    11

    Re: Clear cell when another changes

    It says False when I hit enter.

  12. #12
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Clear cell when another changes

    Quote Originally Posted by richardson.cr View Post
    It says False when I hit enter.
    Okay, everything will be ok if you enter the below code in immediate window.

    application.EnableEvents

    B'Cos the above code will enable the events. After entering just return to excel and check

  13. #13
    Registered User
    Join Date
    02-15-2011
    Location
    Merseyside
    MS-Off Ver
    Excel 2011 For Mac
    Posts
    11

    Re: Clear cell when another changes

    I went to the immediate window again and entered the code,

    It comes up with an error that says Compile Error: Invalid Use of property.

    Sorry for the hassle!

  14. #14
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Clear cell when another changes

    Oops sorry for it.... little bit collapsed bcos of answering multiple threads

    Try this one

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    02-15-2011
    Location
    Merseyside
    MS-Off Ver
    Excel 2011 For Mac
    Posts
    11

    Re: Clear cell when another changes

    Thank you, that now seems to work.

    I have only one other question,

    When you change the cell in the first column, it does clear the 2nd column, but it then puts a selection box around it but leaves the little drop down box arrow from the first column. Is there a way to either make it show the drop down box icon for the second column instead or not put the selection box around the 2nd column cell?

    If that doesn't make sense I'll post an image!

  16. #16
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Clear cell when another changes

    Replace the previous suggested code with the below one

    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    02-15-2011
    Location
    Merseyside
    MS-Off Ver
    Excel 2011 For Mac
    Posts
    11

    Re: Clear cell when another changes

    Hi,

    Did that and it's seems to have gone really wrong now.

    As soon as I tried it, it said Runtime Error 1004, Command not available in Excel for Macintosh.

    After that the blanking doesn't work at all.

    Sorry!!

  18. #18
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Clear cell when another changes

    Try this... Untested since I am not using to Mac Excel

    Please Login or Register  to view this content.
    Send Key Source For Mac:-

    Post #10 of the below link....

    http://www.mrexcel.com/forum/excel-q...dkeys-mac.html

  19. #19
    Registered User
    Join Date
    02-15-2011
    Location
    Merseyside
    MS-Off Ver
    Excel 2011 For Mac
    Posts
    11

    Re: Clear cell when another changes

    Thanks so much for trying again, I really appreciate it. Unfortunately that one doesn't work at all either.

    The great shame is it would be perfect with the original thing you wrote for me if it weren't for the weird highlighted cell thing it does. Ie if I change a cell in column B and hit enter, the drop down arrows appear to the right of the cell below like they should, but the selection/highlighted box is around the cell in column c on the row above (i.e. the one the macro just blanked).

    Ah well, I can live with it and it works, so I won't waste anymore of your time.

    Many thanks

    c

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 3
    Last Post: 08-16-2014, 09:55 AM
  2. Replies: 1
    Last Post: 06-21-2013, 04:05 AM
  3. [SOLVED] Clear button, add warning dialogue box that asks: Are you sure you want to clear?
    By nenadmail in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-21-2012, 02:41 PM
  4. Macro that will clear contents of cell based on format of text in adjacent cell
    By judasdac in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-12-2012, 01:56 AM
  5. Button to clear sheet and automatic clear rows
    By sandbach in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-29-2010, 02:06 PM

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