+ Reply to Thread
Results 1 to 6 of 6

Clear a range of cells if a value is posted in another cell

  1. #1
    Registered User
    Join Date
    08-30-2012
    Location
    Meriden, England
    MS-Off Ver
    Excel 2016
    Posts
    20

    Clear a range of cells if a value is posted in another cell

    Hi to All,
    As a frustrated VBA "Virgin" I would be so grateful if one of you gurus could help me out.
    Bearing in mind I am a real beginner (but very enthusiastic) could you walk me though the steps I need to do to achieve this hopefully straightforward task.

    I have a cell in my worksheet (called Sheet 1), in the sheet I have a basic Excel formula that will change cell T40 that usually reads "0" to a "1" if the criteria I want is met (in effect a trigger cell(?))]

    So.......

    When T40 is displaying a "1" I want to clear cells T5:T38

    My newbie questions is once I have this code, where exactly should I put it.

    I'd be really grateful for any help. Thanks in advance
    Steve

  2. #2
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Clear a range of cells if a value is posted in another cell

    Hello Steve,

    A basic code such as follows would do the task for you:-


    Please Login or Register  to view this content.
    To implement the code, go to the Developer tab and over to the far left, select Visual Basic. This will open the VB Editor (you can also use Alt + F11 to open it). Once open, select Insert. From the menu that appears, select Module. The big grey field to the right will change to white. In this field, paste the above code. Go back to your spread sheet, press Alt + F8 and the Macro dialogue box will appear. Click on "Run" to execute the code. You could, of course, create a button to assign the macro to and run the code by clicking on the button.

    Every time that cell T40 has a 1 in it, the code will execute otherwise, nothing will happen.

    I hope that this helps.

    Cheerio,
    vcoolio.

  3. #3
    Registered User
    Join Date
    08-30-2012
    Location
    Meriden, England
    MS-Off Ver
    Excel 2016
    Posts
    20

    Re: Clear a range of cells if a value is posted in another cell

    Thanks very much for your help vcoolio.
    It works a treat, except I need it to run all the time. I didn't explain very well.
    The sheet is hooked up to an api that is constantly changing the figures. So what I need it to do is change whenever a "1" appears.
    When I applied this code and followed your instructions, it cleared the cells, the next time the "1" appeared nothing happened.
    It's probably my mistake somewhere.
    Cheers
    Steve

  4. #4
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Clear a range of cells if a value is posted in another cell

    Hello Steve,

    When I applied this code and followed your instructions, it cleared the cells, the next time the "1" appeared nothing happened.
    You actually have to run the code again.

    However, a Worksheet_Change event may be a better option considering your updated explanation.

    Make the following change to the code in post #2:-

    Please Login or Register  to view this content.
    Now, right click on the sheet tab and select view code. In the big white field that appears, paste the following:-


    Please Login or Register  to view this content.
    You now don't need to do anything. Every time the value in T40 changes to "1", the range T5:T38 will clear.

    Cheerio,
    vcoolio.

  5. #5
    Registered User
    Join Date
    08-30-2012
    Location
    Meriden, England
    MS-Off Ver
    Excel 2016
    Posts
    20

    Re: Clear a range of cells if a value is posted in another cell

    Perfect!!!
    Really appreciate the time you have taken to help me vcoolio
    Cheers
    Steve

  6. #6
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Clear a range of cells if a value is posted in another cell

    Hello Steve,

    You're welcome. Glad that I could help.

    Cheerio,
    vcoolio.

+ 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. copying cells in range and and paste to next clear cell
    By 1c3m4n in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-01-2016, 07:02 PM
  2. Clear range based on cell value - clearing cells out of specified range
    By CADiphile in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-15-2013, 02:48 PM
  3. Replies: 1
    Last Post: 06-21-2013, 04:05 AM
  4. [SOLVED] VBA Clear Cells for one range if cell in other range is blank
    By DoodlesMama in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-03-2013, 06:23 PM
  5. [SOLVED] Macro needed to clear cells in range based on value of cells in another range
    By msmith7113 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-05-2013, 12:32 AM
  6. posted data in a range of cells can't change after three days
    By andycapp in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-18-2006, 09:30 AM
  7. [SOLVED] Posted date in a range of cells that can't be edited after three d
    By andycapp in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-18-2006, 02:25 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