+ Reply to Thread
Results 1 to 8 of 8

Need a macro to clear contents of a cell if its value is the same as the previous cell

  1. #1
    Registered User
    Join Date
    02-14-2013
    Location
    Riverside, CA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Need a macro to clear contents of a cell if its value is the same as the previous cell

    Hi,

    I would like to create a macro that would clear contents of a cell if its value is the same as the same cell in the previous row.

    For example I have a spreadsheet (query output) that repeats the data across columns A-E because column F has a different value. I would like to compare the ID's and if the same, clear the contents of all cells in the repeated row, except the contents of cells in F column. SampleOf_Clear_Contents_IfSame_As_Previous.xlsx

    Thanks in advance for your expertise.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,774

    Re: Need a macro to clear contents of a cell if its value is the same as the previous cell

    If your objective is to clear those fields for printing purposes, it would be safer just to use Conditional Formatting to set the font and background colour to white, thus hiding the content.

    Other than that, I think that deleting the content would be a mistake. Whilst it may look pretty, it will be useless in terms of analysing the data as you will no longer have the "linking" data fields.

    And, more often than not, a sequence such as you have in column F would be a formula based on the content of, say, column A ... though it isn't in this case.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Need a macro to clear contents of a cell if its value is the same as the previous cell

    I agree with TMS..

    its a good suggestion..

    still here is a "Junky-Funky" code for the same..

    Please Login or Register  to view this content.
    Regards!
    =DEC2HEX(3563)

    If you like someone's answer, click the star to give them a reputation point for that answer...

  4. #4
    Registered User
    Join Date
    02-14-2013
    Location
    Riverside, CA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Need a macro to clear contents of a cell if its value is the same as the previous cell

    Thank you for the suggestion. If it were merely for printing, I agree. This spreadsheet will be published for searching by users. If I don't clear some content, it makes searching through all of the duplicates too time consuming. I was thinking that if I could clear contents of D and E , or at least E which truly has the bulk of the text in the real spreadsheet, based on ID that would work.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,774

    Re: Need a macro to clear contents of a cell if its value is the same as the previous cell

    One way then:

    Please Login or Register  to view this content.

    Regards, TMS

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Need a macro to clear contents of a cell if its value is the same as the previous cell

    FWIW:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-14-2013
    Location
    Riverside, CA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Need a macro to clear contents of a cell if its value is the same as the previous cell

    Thank you all for the responses. I was able to clear the cells and publish the list.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,774

    Re: Need a macro to clear contents of a cell if its value is the same as the previous cell

    You're welcome.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ 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. Need a macro to add 1 to active cell based on previous cell contents
    By wtom in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-20-2014, 12:16 AM
  2. [SOLVED] Macro - Clear cell contents based on other cell
    By 97hills in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-02-2013, 10:58 AM
  3. [SOLVED] Macro to clear cell contents in all but 1 column of specified rows
    By HelderPT in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-19-2012, 12:47 PM
  4. [SOLVED] Clear contents of last used cell in a range and those previous to it (excel 2003)
    By chris_norton in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-17-2012, 02:06 PM
  5. 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