+ Reply to Thread
Results 1 to 4 of 4

Clearing the contents of one cell, if another cell is blank

  1. #1
    Registered User
    Join Date
    05-18-2021
    Location
    Cheshire
    MS-Off Ver
    2016
    Posts
    2

    Clearing the contents of one cell, if another cell is blank

    Hello All,

    This is my first post here. I hope someone will be able to help.

    I would like to be able to write a macro which will clear the contents of two cells (say L2 and M2), if another cell (say O2) is blank. If the other cell is not blank, I would like to leave the first cell as it is. I want to do this for every row in my spreadsheet (I have about 250 rows in my spreadsheet but that is not fixed).

    I can think of what I would like to do in my head, but not what sort of macro would help me do it. As you may have guessed, I am very new to this. This is what I would like to achieve

    Set a row count (i) to 2 (my data starts at row 2)
    Loop while cell L(i) is not blank
    If Cell O(i) is blank
    Set cells L(i) and M(i) to blank
    Else
    Do nothing
    add 1 to my row count
    end loop

    I hope this makes sense - I have attached a pic of the data which I hope will make it more clear

    Many thanks
    AlysExcel Problem.PNG
    Last edited by AWardSand; 05-18-2021 at 05:51 AM.

  2. #2
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: Clearing the contents of one cell, if another cell is blank

    This will somehow do what you have in mind. The macro, to be copied in the vba module of the sheet, will trigger every time you change something in that sheet since it checks the state of the event Worksheet_Change.
    Please Login or Register  to view this content.
    Last edited by rollis13; 05-18-2021 at 06:12 AM.

  3. #3
    Registered User
    Join Date
    05-18-2021
    Location
    Cheshire
    MS-Off Ver
    2016
    Posts
    2

    Re: Clearing the contents of one cell, if another cell is blank

    Thank you so much, this does exactly what I hoped it would. So helpful, I really appreciate your time.

    Alys

  4. #4
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: Clearing the contents of one cell, if another cell is blank

    Glad having been of some help .

+ 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. Clearing Cell Contents
    By dandavis1 in forum Excel General
    Replies: 1
    Last Post: 09-11-2008, 05:35 AM
  2. Clearing contents of cell by cell refererance in other sheet
    By Kyles_treos in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-11-2008, 10:23 AM
  3. [SOLVED] Clearing cell contents
    By Gina in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-04-2006, 04:55 AM
  4. Selectively Clearing cell contents
    By jdd in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-21-2006, 11:10 PM
  5. Macro Help for Deleting Blank Rows & Clearing Cell Contents
    By ksp in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-13-2006, 01:25 AM
  6. Clearing cell contents on CellUpdate
    By loopoo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-14-2005, 09:20 AM
  7. Clearing Contents of Cell
    By Burt in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-04-2005, 10:06 AM
  8. Clearing cell contents from within a function
    By David.S in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-05-2005, 11:22 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