+ Reply to Thread
Results 1 to 10 of 10

Clear cell contents if a cell is =0

  1. #1
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    2010
    Posts
    496

    Clear cell contents if a cell is =0

    Hello,
    Need a real time VBA on this....

    if A1=0, then clear contents in B1:B5

    Also I need a seperate one for ...
    if A1=0, then clear content in B1

    Thanks
    Last edited by Rocky2013; 04-24-2018 at 03:18 PM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Clear cell contents if a cell is =0

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    2010
    Posts
    496

    Re: Clear cell contents if a cell is =0

    Hi,
    For some reason, it does not work for me. I use scroll bar to drag the value up and down. When A1=0,
    I want the values in B1:B5 to be deleted.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Clear cell contents if a cell is =0

    You need to put Alan's macro in a standard module and assign the macro to the spinner object (Spinner 2) you have in cell A1 by right-clicking it and then clicking Assign Macro from the short-cut menu.
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  5. #5
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    2010
    Posts
    496

    Re: Clear cell contents if a cell is =0

    Hi Trebor76,
    I put marco in sheet1, now I deleted marco and copied to Module,
    I already assign marco to spinner object. It still does not work.

    I preset A1 to 3, then I start to click the down arrow of spinner,
    until it shows 0, values but B1:B5 do not get deleted.

    Did I do something wrong?
    Attached Files Attached Files
    Last edited by Rocky2013; 04-22-2018 at 09:38 PM.

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Clear cell contents if a cell is =0

    It appears that you are looking for worksheet change event. The following will do that if you change the spinner to a manual entry in Cell A1. Worksheet change events do not work with spinners or data validation type of events. There needs to be a physical change.

    Please Login or Register  to view this content.

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Clear cell contents if a cell is =0

    Quote Originally Posted by Rocky2013 View Post
    Hi Trebor76,
    I put marco in sheet1, now I deleted marco and copied to Module,
    I already assign marco to spinner object. It still does not work.

    I preset A1 to 3, then I start to click the down arrow of spinner,
    until it shows 0, values but B1:B5 do not get deleted.

    Did I do something wrong?
    You need to reassign the Spinner's macro to Rocky1; the same macro you copied to module 1. After that it works fine.
    Attached Files Attached Files
    Last edited by AlphaFrog; 04-22-2018 at 11:15 PM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  8. #8
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    2010
    Posts
    496

    Re: Clear cell contents if a cell is =0

    Hi AlphaFrog,
    Thanks it works. I did try that it does not work for me. I must did
    something wrong.

    I like to extend my request, I need an undo to recover the numbers that were deleted.

    Thanks
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    2010
    Posts
    496

    Re: Clear cell contents if a cell is =0

    Quote Originally Posted by alansidman View Post
    It appears that you are looking for worksheet change event. The following will do that if you change the spinner to a manual entry in Cell A1. Worksheet change events do not work with spinners or data validation type of events. There needs to be a physical change.

    Please Login or Register  to view this content.
    Hi alansidman,
    I manual type in 0, values deleted from B1:B5. But there is a "Run-time error '13': Type mismatch" popup message.
    Also looking an undo.

    Thanks
    Attached Files Attached Files

  10. #10
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Clear cell contents if a cell is =0

    try this modified code

    Please Login or Register  to view this content.
    In order to have an undo when using a macro/vba, you will need to store the deleted values somewhere and then copy and paste them back. Once you delete something with a VBA method, there is no undo. So now that you know, where would you like to store the values that are currently in B1:B5

+ 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. [SOLVED] Needing VBA code to clear contents of cell when the contents of another cell is cleared
    By jeh0714 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-15-2016, 03:49 PM
  2. Clear merged cell contents in comand button(clear all)
    By mohan_984 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-25-2015, 10:39 AM
  3. VBA to clear contents of the cell in a column of data in a cell starts with specific word.
    By winmaxservices1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-03-2015, 08:25 AM
  4. [SOLVED] VBA Help needed to clear cell contents if the Column “B” cell is blank
    By krjoshi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-19-2014, 04:54 AM
  5. [SOLVED] move down column and for every blank cell, clear contents of cell to the left
    By hopefulhart in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-01-2014, 11:23 AM
  6. Clear contents in one cell when contents of another cell are deleted
    By rlbush2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-22-2012, 10:29 PM
  7. 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

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