+ Reply to Thread
Results 1 to 10 of 10

Delete Macro if Row contains Value in Column B

  1. #1
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    Work Office 365 Home 2019
    Posts
    427

    Delete Macro if Row contains Value in Column B

    Greetings Hive mind,

    I have a spreadsheet where the value in cell C5 of the Tab called "input" influences the value in Column B of the tab called Impacted Sheet

    I'm looking for a macro that, when activated, will look for the value "N/A" in column B and, if it is present, will delete the entire row.

    There are three possible states for the "input cell", DP, DC and JDC

    In my example workbook I've included the desired output for each state. These are for example purposes as the changes would be made on the "Impacted Sheet" Tab

    Many thanks and have a wonderful weekend.

    MM
    Attached Files Attached Files

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Delete Macro if Row contains Value in Column B

    Please Login or Register  to view this content.
    Last edited by sintek; 05-07-2022 at 06:25 AM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

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

    Re: Delete Macro if Row contains Value in Column B

    Hi to all.
    Oh, I'm terribly late, anyway, this is what I came up with:
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    Work Office 365 Home 2019
    Posts
    427

    Re: Delete Macro if Row contains Value in Column B

    Hi Sintek - you help me again

    I see it works by doing a row count. Just as an aside, how would the coding be changed if I only wanted it to do it on a certain number of rows. For example, if I wanted to keep rows 39 through to 43 irrespective of the outcome?

    Thanks

    MM

  5. #5
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Delete Macro if Row contains Value in Column B

    Play around with the red snippet [-1] in code above

  6. #6
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    Work Office 365 Home 2019
    Posts
    427

    Re: Delete Macro if Row contains Value in Column B

    Hi Rollis,

    Nearly there I do appreciate your efforts.

    With your code I have found that it doesn't influence cell b3 and that gets deleted irrespective of what the value may be.

  7. #7
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    Work Office 365 Home 2019
    Posts
    427

    Re: Delete Macro if Row contains Value in Column B

    Brilliant Sintek!

    That works, but it deletes the value in Column A, any ideas on how I can retain that?

    MM

    P.S. Rep added :-)

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Delete Macro if Row contains Value in Column B

    but it deletes the value in Column A
    Not sure what you mean...?
    Can only assume your "MERGED CELLS" is causing havoc...
    Hence rule No 1 in Excel...Do Not Use Merged Cells...
    Also why rows 1 and 2 blank...No Headers...Poor sheet setup practice
    Last edited by sintek; 05-07-2022 at 06:46 AM.

  9. #9
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    Work Office 365 Home 2019
    Posts
    427

    Re: Delete Macro if Row contains Value in Column B

    Quote Originally Posted by sintek View Post
    Hence rule No 1 in Excel...Do Not Use Merged Cells...
    Fair Point, well made

    Quote Originally Posted by sintek View Post
    Also why rows 1 and 2 blank...No Headers...Poor Sheet setup practice
    It's blank in the example, on my 'working sheet' it will have headers etc. I deliberately set the example in the way I do so that I can identify when something is coded as "B3:B" as opposed to "B:B". This helps me to understand the workings of the macro better and, hopefully, some of it will sink in to my aged brain and, who knows, it may even stay there for a little while

  10. #10
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Delete Macro if Row contains Value in Column B

    Future advice...Always upload a sample file depicting your actual file setup...99% of the time users are not able to edit code to fit actual file setup...
    Thanks for rep +
    Last edited by sintek; 05-07-2022 at 09:54 AM.

+ 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] Macro to delete column if...
    By capson in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-15-2013, 06:48 AM
  2. [SOLVED] Macro to count unique values in a column, enter it in next column, then delete duplicates
    By pmorisse in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-25-2013, 03:27 PM
  3. Macro to delete column in front of yellow highlighted column
    By Getsuko Teng in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-06-2012, 02:30 PM
  4. Run Macro Automatically When delete row , changes cell,delete column
    By elevisse in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-27-2012, 07:42 AM
  5. Macro to delete certain columns and delete rows based on time in another column
    By beepbeep27 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-12-2012, 11:47 AM
  6. Macro to delete first row and insert column after a certain number of column
    By arnab0711 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-26-2011, 08:36 PM
  7. Macro to delete row if value in column J =0
    By annep in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-01-2006, 07:26 PM

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