+ Reply to Thread
Results 1 to 12 of 12

clear cell contents based on conditions

  1. #1
    Forum Contributor
    Join Date
    10-27-2010
    Location
    singapore
    MS-Off Ver
    Excel 2003
    Posts
    107

    clear cell contents based on conditions

    I would like to clear any cell that only contains “?” and/or “,”.
    Take a look at the image below:
    1.JPG

    From the image above we can see that in cell D4, E1, F2, F3 and F4 the contents consist of “?” and/or “,”, so I want my macro to detect such cells and clear its content.

    Do not clear contents of cell that has together with “?” and/or “s” there may be other character. For e.g. from the above image if you look at cell D2 there is other words such as jp6_7, jp6_8, so such cells should not be cleared

    I would like to do this to the entire column D, E and F

    The final outcome should look like the image below
    2.JPG

    I have also attached a sample worksheet,
    Book2.xls
    Sheet 1 shows the initial texts
    Sheet 2 contains a button where the macro should be written
    Sheet 3 shows how the final outcome looks like
    Last edited by darkhorse4321; 11-18-2010 at 10:59 PM.

  2. #2
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161

    Re: clear cell contents based on conditions

    Why not just use the Find & Replace tool found in the EDIT dropdown of the toolbar, search for ? and replace with nothing.
    Not all forums are the same - seek and you shall find

  3. #3
    Forum Contributor
    Join Date
    10-27-2010
    Location
    singapore
    MS-Off Ver
    Excel 2003
    Posts
    107

    Re: clear cell contents based on conditions

    Hi Simon,
    If the cell just contain "?" or ",", i would have used replace tool and changed it with nothing. But the contents in the cell are something like "?,?,?" or "?,?,?,?,?,?" and so on. It is not consistent that's why i can't use replace tool.take a look at the image i uploaded.

  4. #4
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161

    Re: clear cell contents based on conditions

    Are there always numbers contained in cells that also contain ? that you want to keep?

  5. #5
    Forum Contributor
    Join Date
    10-27-2010
    Location
    singapore
    MS-Off Ver
    Excel 2003
    Posts
    107

    Re: clear cell contents based on conditions

    Yes some cells will contain not only numbers but letters too, together with "?" and/or "," and you are right i want to keep these cells.

  6. #6
    Forum Contributor
    Join Date
    10-27-2010
    Location
    singapore
    MS-Off Ver
    Excel 2003
    Posts
    107

    Re: clear cell contents based on conditions

    If i'm not wrong. The structure for my codes should roughly look like this:

    If a cell only contain question mark "?" and/or comma "," then delete the cell content
    else
    do nothing
    loop the above step till the last row of column D,E and F.

    Just that i don't know how to translate this into code form.

  7. #7
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161

    Re: clear cell contents based on conditions

    Well as long as the cells that you want to keep will ALWAYS have at least one number in it this should work
    Please Login or Register  to view this content.
    Last edited by Simon Lloyd; 11-16-2010 at 12:59 PM.

  8. #8
    Forum Contributor
    Join Date
    10-27-2010
    Location
    singapore
    MS-Off Ver
    Excel 2003
    Posts
    107

    Re: clear cell contents based on conditions

    Thanks Simon,your codes are working fine, as long the cell has a number in it, the cell won't get cleared.

    But is it possible to include letters in it too. For e.g. if the cell has a letter (a,b,c...z) in it then the cell shouldn't be cleared

  9. #9
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161

    Re: clear cell contents based on conditions

    Not tested as i dont have time
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    10-27-2010
    Location
    singapore
    MS-Off Ver
    Excel 2003
    Posts
    107

    Re: clear cell contents based on conditions

    hi simon, the codes didn't work. There is error in the code.

  11. #11
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161

    Re: clear cell contents based on conditions

    Like i said, i didnt have time to test it, thsi works or seems to work for me:
    Please Login or Register  to view this content.
    Last edited by Simon Lloyd; 11-18-2010 at 08:43 PM.

  12. #12
    Forum Contributor
    Join Date
    10-27-2010
    Location
    singapore
    MS-Off Ver
    Excel 2003
    Posts
    107

    Re: clear cell contents based on conditions

    Thanks simon. It worked for me too

+ 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