If a cell has a certain value XXX, how do I delete the rows that don't have the value XXX?












0















In the posted example, if for Jane and David I'm only interested in rows with "Total" in column B, how do I remove the rows that do not contain "Total" in column B. I would like to apply this functionality to multiple sheets within a workbook.



Example










share|improve this question




















  • 1





    The easiest would be to "Filter" your results, highlight cells A1, B1 and C1 then use the "Filter" option in the "Sort & Filter" area of the "DATA" pane. If you want to know how many items have been picked then you want a COUNTIF() formula. This is a comment as your question is not that clear.

    – Kevin Anthony Oppegaard Rose
    Dec 19 '18 at 11:36











  • Sound like he want us to script him a VBA Function

    – dmb
    Dec 19 '18 at 12:19











  • Your title talks about deleting columns, but your question talks about deleting rows Which is it???

    – Gary's Student
    Dec 19 '18 at 14:06













  • Typically, totals are dynamic, not data. If that's the case here, you would have to use filtering rather than deleting rows, otherwise the totals will be zero.

    – fixer1234
    Dec 20 '18 at 20:37
















0















In the posted example, if for Jane and David I'm only interested in rows with "Total" in column B, how do I remove the rows that do not contain "Total" in column B. I would like to apply this functionality to multiple sheets within a workbook.



Example










share|improve this question




















  • 1





    The easiest would be to "Filter" your results, highlight cells A1, B1 and C1 then use the "Filter" option in the "Sort & Filter" area of the "DATA" pane. If you want to know how many items have been picked then you want a COUNTIF() formula. This is a comment as your question is not that clear.

    – Kevin Anthony Oppegaard Rose
    Dec 19 '18 at 11:36











  • Sound like he want us to script him a VBA Function

    – dmb
    Dec 19 '18 at 12:19











  • Your title talks about deleting columns, but your question talks about deleting rows Which is it???

    – Gary's Student
    Dec 19 '18 at 14:06













  • Typically, totals are dynamic, not data. If that's the case here, you would have to use filtering rather than deleting rows, otherwise the totals will be zero.

    – fixer1234
    Dec 20 '18 at 20:37














0












0








0








In the posted example, if for Jane and David I'm only interested in rows with "Total" in column B, how do I remove the rows that do not contain "Total" in column B. I would like to apply this functionality to multiple sheets within a workbook.



Example










share|improve this question
















In the posted example, if for Jane and David I'm only interested in rows with "Total" in column B, how do I remove the rows that do not contain "Total" in column B. I would like to apply this functionality to multiple sheets within a workbook.



Example







microsoft-excel worksheet-function






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 20 '18 at 1:42







user975479

















asked Dec 19 '18 at 11:31









user975479user975479

11




11








  • 1





    The easiest would be to "Filter" your results, highlight cells A1, B1 and C1 then use the "Filter" option in the "Sort & Filter" area of the "DATA" pane. If you want to know how many items have been picked then you want a COUNTIF() formula. This is a comment as your question is not that clear.

    – Kevin Anthony Oppegaard Rose
    Dec 19 '18 at 11:36











  • Sound like he want us to script him a VBA Function

    – dmb
    Dec 19 '18 at 12:19











  • Your title talks about deleting columns, but your question talks about deleting rows Which is it???

    – Gary's Student
    Dec 19 '18 at 14:06













  • Typically, totals are dynamic, not data. If that's the case here, you would have to use filtering rather than deleting rows, otherwise the totals will be zero.

    – fixer1234
    Dec 20 '18 at 20:37














  • 1





    The easiest would be to "Filter" your results, highlight cells A1, B1 and C1 then use the "Filter" option in the "Sort & Filter" area of the "DATA" pane. If you want to know how many items have been picked then you want a COUNTIF() formula. This is a comment as your question is not that clear.

    – Kevin Anthony Oppegaard Rose
    Dec 19 '18 at 11:36











  • Sound like he want us to script him a VBA Function

    – dmb
    Dec 19 '18 at 12:19











  • Your title talks about deleting columns, but your question talks about deleting rows Which is it???

    – Gary's Student
    Dec 19 '18 at 14:06













  • Typically, totals are dynamic, not data. If that's the case here, you would have to use filtering rather than deleting rows, otherwise the totals will be zero.

    – fixer1234
    Dec 20 '18 at 20:37








1




1





The easiest would be to "Filter" your results, highlight cells A1, B1 and C1 then use the "Filter" option in the "Sort & Filter" area of the "DATA" pane. If you want to know how many items have been picked then you want a COUNTIF() formula. This is a comment as your question is not that clear.

– Kevin Anthony Oppegaard Rose
Dec 19 '18 at 11:36





The easiest would be to "Filter" your results, highlight cells A1, B1 and C1 then use the "Filter" option in the "Sort & Filter" area of the "DATA" pane. If you want to know how many items have been picked then you want a COUNTIF() formula. This is a comment as your question is not that clear.

– Kevin Anthony Oppegaard Rose
Dec 19 '18 at 11:36













Sound like he want us to script him a VBA Function

– dmb
Dec 19 '18 at 12:19





Sound like he want us to script him a VBA Function

– dmb
Dec 19 '18 at 12:19













Your title talks about deleting columns, but your question talks about deleting rows Which is it???

– Gary's Student
Dec 19 '18 at 14:06







Your title talks about deleting columns, but your question talks about deleting rows Which is it???

– Gary's Student
Dec 19 '18 at 14:06















Typically, totals are dynamic, not data. If that's the case here, you would have to use filtering rather than deleting rows, otherwise the totals will be zero.

– fixer1234
Dec 20 '18 at 20:37





Typically, totals are dynamic, not data. If that's the case here, you would have to use filtering rather than deleting rows, otherwise the totals will be zero.

– fixer1234
Dec 20 '18 at 20:37










3 Answers
3






active

oldest

votes


















0














Your simplest approach is to simply sort on the value you want and delete all the rows before that value, then all the ones after it which will leave only the rows with exactly it.



Of course, this being Excel, you can do each little bit of that slightly differently with wee bit more work. For instance, insert a "helper" column somewhere convenient (right next to your column of interest for example) and quickly write an IF test for the value with "" for failure to find it. Then copy, or fill, the entire column with the formula (each testing that row's cell), sort on the helper column and all the rows you want to delete are together rather than in two bunches. Which of your various options seems easier in your circumstance and preference is the way you might go.



If you need a macro to do it, follow the same concept. In the macro simply test the first cell in your column of interest for the value and if it is NOT found have the macro delete that row, then loop until you reach the end of data. If no cell can ever be blank in that column, you can test for blankness and quit when found. But... if a cell could be empty, you will need to try something else. Any of a variety of things could work depending upon your table and the other cells' characteristics, but you could also just start the macro on the last possible cell, chosen by your brain, and work upward (including a test for the row number each time so you can stop at, say, row 2 i fyou have headers rather than deleting our header row and then permanently looping on the first row).



Or combine the two. Sort the data on that column, in a macro, look for the first occurence of the desired value, delete all the DATA rows above that value, then test until the first failure, and delete all the rows afterwards.



So many ways. My approach would be the very first one for my own working. For a spreadsheet I'm giving to someone else to use, I'd modify that by trying to automate for him. Or... depends on the user, knowledgeable vs. newbie, boss vs. Jimmy from janitorial. That kind of thing.






share|improve this answer































    0














    Thank you all for your help. I ended up doing the following:




    1. Use conditional formatting to highlight all cells with duplicate names

    2. Sort cells by colour, then sort by name of apple

    3. Shift select all rows containing a highlighted cell, that did not have "Total" in the apple column.


    This process has been relatively quick for large datasets.






    share|improve this answer
























    • It's nice to find the Self Answer, it's your prerogative to opt the method but once you try the MACRO I've posted is TIME SAVER and a One Click Solution. ☺

      – Rajesh S
      Dec 20 '18 at 6:48











    • You are right, and I will try the macro as well! I am embarrassingly intimidated by macros but am trying my best to learn. :)

      – user975479
      Dec 22 '18 at 0:52



















    0














    I would like to suggest a MACRO, which the best and fastest method to Delete all rows from all the Sheets, doesn't contains text TOTAL in specific Column B.



    Sub Delete_Rows()

    Dim rng As Range, cell As Range, del As Range
    Dim sht As Worksheet

    For X = 1 To 10
    Set sht = Sheets(X)
    Set del = Nothing

    Set rng = Intersect(sht.Range("B1:B9"), sht.UsedRange)

    For Each cell In rng.Cells

    If (cell.Value) <> "Total" Then
    If del Is Nothing Then
    Set del = cell
    Else
    Set del = Union(del, cell)
    End If
    End If

    Next cell

    If Not del Is Nothing Then del.EntireRow.Delete
    Next X

    End Sub


    How it works:




    • At any Sheet Press Alt+F11 to open VB Editor then Copy & Paste this Code as Standard Module.

    • Before you RUN the Macro, insure that the Search String Total is available in Range B1:B9 in all the Sheets, from where you are
      trying to Delete Rows.


    Note:




    • For X = 1 to 10 indicated that MACRO will search TOTAL in 10 Worksheets, which is editable.


    • You may also adjust/alter the Search Range B1:B9 and the String Total as you need.







    share|improve this answer

























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "3"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1385890%2fif-a-cell-has-a-certain-value-xxx-how-do-i-delete-the-rows-that-dont-have-the%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Your simplest approach is to simply sort on the value you want and delete all the rows before that value, then all the ones after it which will leave only the rows with exactly it.



      Of course, this being Excel, you can do each little bit of that slightly differently with wee bit more work. For instance, insert a "helper" column somewhere convenient (right next to your column of interest for example) and quickly write an IF test for the value with "" for failure to find it. Then copy, or fill, the entire column with the formula (each testing that row's cell), sort on the helper column and all the rows you want to delete are together rather than in two bunches. Which of your various options seems easier in your circumstance and preference is the way you might go.



      If you need a macro to do it, follow the same concept. In the macro simply test the first cell in your column of interest for the value and if it is NOT found have the macro delete that row, then loop until you reach the end of data. If no cell can ever be blank in that column, you can test for blankness and quit when found. But... if a cell could be empty, you will need to try something else. Any of a variety of things could work depending upon your table and the other cells' characteristics, but you could also just start the macro on the last possible cell, chosen by your brain, and work upward (including a test for the row number each time so you can stop at, say, row 2 i fyou have headers rather than deleting our header row and then permanently looping on the first row).



      Or combine the two. Sort the data on that column, in a macro, look for the first occurence of the desired value, delete all the DATA rows above that value, then test until the first failure, and delete all the rows afterwards.



      So many ways. My approach would be the very first one for my own working. For a spreadsheet I'm giving to someone else to use, I'd modify that by trying to automate for him. Or... depends on the user, knowledgeable vs. newbie, boss vs. Jimmy from janitorial. That kind of thing.






      share|improve this answer




























        0














        Your simplest approach is to simply sort on the value you want and delete all the rows before that value, then all the ones after it which will leave only the rows with exactly it.



        Of course, this being Excel, you can do each little bit of that slightly differently with wee bit more work. For instance, insert a "helper" column somewhere convenient (right next to your column of interest for example) and quickly write an IF test for the value with "" for failure to find it. Then copy, or fill, the entire column with the formula (each testing that row's cell), sort on the helper column and all the rows you want to delete are together rather than in two bunches. Which of your various options seems easier in your circumstance and preference is the way you might go.



        If you need a macro to do it, follow the same concept. In the macro simply test the first cell in your column of interest for the value and if it is NOT found have the macro delete that row, then loop until you reach the end of data. If no cell can ever be blank in that column, you can test for blankness and quit when found. But... if a cell could be empty, you will need to try something else. Any of a variety of things could work depending upon your table and the other cells' characteristics, but you could also just start the macro on the last possible cell, chosen by your brain, and work upward (including a test for the row number each time so you can stop at, say, row 2 i fyou have headers rather than deleting our header row and then permanently looping on the first row).



        Or combine the two. Sort the data on that column, in a macro, look for the first occurence of the desired value, delete all the DATA rows above that value, then test until the first failure, and delete all the rows afterwards.



        So many ways. My approach would be the very first one for my own working. For a spreadsheet I'm giving to someone else to use, I'd modify that by trying to automate for him. Or... depends on the user, knowledgeable vs. newbie, boss vs. Jimmy from janitorial. That kind of thing.






        share|improve this answer


























          0












          0








          0







          Your simplest approach is to simply sort on the value you want and delete all the rows before that value, then all the ones after it which will leave only the rows with exactly it.



          Of course, this being Excel, you can do each little bit of that slightly differently with wee bit more work. For instance, insert a "helper" column somewhere convenient (right next to your column of interest for example) and quickly write an IF test for the value with "" for failure to find it. Then copy, or fill, the entire column with the formula (each testing that row's cell), sort on the helper column and all the rows you want to delete are together rather than in two bunches. Which of your various options seems easier in your circumstance and preference is the way you might go.



          If you need a macro to do it, follow the same concept. In the macro simply test the first cell in your column of interest for the value and if it is NOT found have the macro delete that row, then loop until you reach the end of data. If no cell can ever be blank in that column, you can test for blankness and quit when found. But... if a cell could be empty, you will need to try something else. Any of a variety of things could work depending upon your table and the other cells' characteristics, but you could also just start the macro on the last possible cell, chosen by your brain, and work upward (including a test for the row number each time so you can stop at, say, row 2 i fyou have headers rather than deleting our header row and then permanently looping on the first row).



          Or combine the two. Sort the data on that column, in a macro, look for the first occurence of the desired value, delete all the DATA rows above that value, then test until the first failure, and delete all the rows afterwards.



          So many ways. My approach would be the very first one for my own working. For a spreadsheet I'm giving to someone else to use, I'd modify that by trying to automate for him. Or... depends on the user, knowledgeable vs. newbie, boss vs. Jimmy from janitorial. That kind of thing.






          share|improve this answer













          Your simplest approach is to simply sort on the value you want and delete all the rows before that value, then all the ones after it which will leave only the rows with exactly it.



          Of course, this being Excel, you can do each little bit of that slightly differently with wee bit more work. For instance, insert a "helper" column somewhere convenient (right next to your column of interest for example) and quickly write an IF test for the value with "" for failure to find it. Then copy, or fill, the entire column with the formula (each testing that row's cell), sort on the helper column and all the rows you want to delete are together rather than in two bunches. Which of your various options seems easier in your circumstance and preference is the way you might go.



          If you need a macro to do it, follow the same concept. In the macro simply test the first cell in your column of interest for the value and if it is NOT found have the macro delete that row, then loop until you reach the end of data. If no cell can ever be blank in that column, you can test for blankness and quit when found. But... if a cell could be empty, you will need to try something else. Any of a variety of things could work depending upon your table and the other cells' characteristics, but you could also just start the macro on the last possible cell, chosen by your brain, and work upward (including a test for the row number each time so you can stop at, say, row 2 i fyou have headers rather than deleting our header row and then permanently looping on the first row).



          Or combine the two. Sort the data on that column, in a macro, look for the first occurence of the desired value, delete all the DATA rows above that value, then test until the first failure, and delete all the rows afterwards.



          So many ways. My approach would be the very first one for my own working. For a spreadsheet I'm giving to someone else to use, I'd modify that by trying to automate for him. Or... depends on the user, knowledgeable vs. newbie, boss vs. Jimmy from janitorial. That kind of thing.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 20 '18 at 1:46









          RoyRoy

          1




          1

























              0














              Thank you all for your help. I ended up doing the following:




              1. Use conditional formatting to highlight all cells with duplicate names

              2. Sort cells by colour, then sort by name of apple

              3. Shift select all rows containing a highlighted cell, that did not have "Total" in the apple column.


              This process has been relatively quick for large datasets.






              share|improve this answer
























              • It's nice to find the Self Answer, it's your prerogative to opt the method but once you try the MACRO I've posted is TIME SAVER and a One Click Solution. ☺

                – Rajesh S
                Dec 20 '18 at 6:48











              • You are right, and I will try the macro as well! I am embarrassingly intimidated by macros but am trying my best to learn. :)

                – user975479
                Dec 22 '18 at 0:52
















              0














              Thank you all for your help. I ended up doing the following:




              1. Use conditional formatting to highlight all cells with duplicate names

              2. Sort cells by colour, then sort by name of apple

              3. Shift select all rows containing a highlighted cell, that did not have "Total" in the apple column.


              This process has been relatively quick for large datasets.






              share|improve this answer
























              • It's nice to find the Self Answer, it's your prerogative to opt the method but once you try the MACRO I've posted is TIME SAVER and a One Click Solution. ☺

                – Rajesh S
                Dec 20 '18 at 6:48











              • You are right, and I will try the macro as well! I am embarrassingly intimidated by macros but am trying my best to learn. :)

                – user975479
                Dec 22 '18 at 0:52














              0












              0








              0







              Thank you all for your help. I ended up doing the following:




              1. Use conditional formatting to highlight all cells with duplicate names

              2. Sort cells by colour, then sort by name of apple

              3. Shift select all rows containing a highlighted cell, that did not have "Total" in the apple column.


              This process has been relatively quick for large datasets.






              share|improve this answer













              Thank you all for your help. I ended up doing the following:




              1. Use conditional formatting to highlight all cells with duplicate names

              2. Sort cells by colour, then sort by name of apple

              3. Shift select all rows containing a highlighted cell, that did not have "Total" in the apple column.


              This process has been relatively quick for large datasets.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Dec 20 '18 at 6:44









              user975479user975479

              11




              11













              • It's nice to find the Self Answer, it's your prerogative to opt the method but once you try the MACRO I've posted is TIME SAVER and a One Click Solution. ☺

                – Rajesh S
                Dec 20 '18 at 6:48











              • You are right, and I will try the macro as well! I am embarrassingly intimidated by macros but am trying my best to learn. :)

                – user975479
                Dec 22 '18 at 0:52



















              • It's nice to find the Self Answer, it's your prerogative to opt the method but once you try the MACRO I've posted is TIME SAVER and a One Click Solution. ☺

                – Rajesh S
                Dec 20 '18 at 6:48











              • You are right, and I will try the macro as well! I am embarrassingly intimidated by macros but am trying my best to learn. :)

                – user975479
                Dec 22 '18 at 0:52

















              It's nice to find the Self Answer, it's your prerogative to opt the method but once you try the MACRO I've posted is TIME SAVER and a One Click Solution. ☺

              – Rajesh S
              Dec 20 '18 at 6:48





              It's nice to find the Self Answer, it's your prerogative to opt the method but once you try the MACRO I've posted is TIME SAVER and a One Click Solution. ☺

              – Rajesh S
              Dec 20 '18 at 6:48













              You are right, and I will try the macro as well! I am embarrassingly intimidated by macros but am trying my best to learn. :)

              – user975479
              Dec 22 '18 at 0:52





              You are right, and I will try the macro as well! I am embarrassingly intimidated by macros but am trying my best to learn. :)

              – user975479
              Dec 22 '18 at 0:52











              0














              I would like to suggest a MACRO, which the best and fastest method to Delete all rows from all the Sheets, doesn't contains text TOTAL in specific Column B.



              Sub Delete_Rows()

              Dim rng As Range, cell As Range, del As Range
              Dim sht As Worksheet

              For X = 1 To 10
              Set sht = Sheets(X)
              Set del = Nothing

              Set rng = Intersect(sht.Range("B1:B9"), sht.UsedRange)

              For Each cell In rng.Cells

              If (cell.Value) <> "Total" Then
              If del Is Nothing Then
              Set del = cell
              Else
              Set del = Union(del, cell)
              End If
              End If

              Next cell

              If Not del Is Nothing Then del.EntireRow.Delete
              Next X

              End Sub


              How it works:




              • At any Sheet Press Alt+F11 to open VB Editor then Copy & Paste this Code as Standard Module.

              • Before you RUN the Macro, insure that the Search String Total is available in Range B1:B9 in all the Sheets, from where you are
                trying to Delete Rows.


              Note:




              • For X = 1 to 10 indicated that MACRO will search TOTAL in 10 Worksheets, which is editable.


              • You may also adjust/alter the Search Range B1:B9 and the String Total as you need.







              share|improve this answer






























                0














                I would like to suggest a MACRO, which the best and fastest method to Delete all rows from all the Sheets, doesn't contains text TOTAL in specific Column B.



                Sub Delete_Rows()

                Dim rng As Range, cell As Range, del As Range
                Dim sht As Worksheet

                For X = 1 To 10
                Set sht = Sheets(X)
                Set del = Nothing

                Set rng = Intersect(sht.Range("B1:B9"), sht.UsedRange)

                For Each cell In rng.Cells

                If (cell.Value) <> "Total" Then
                If del Is Nothing Then
                Set del = cell
                Else
                Set del = Union(del, cell)
                End If
                End If

                Next cell

                If Not del Is Nothing Then del.EntireRow.Delete
                Next X

                End Sub


                How it works:




                • At any Sheet Press Alt+F11 to open VB Editor then Copy & Paste this Code as Standard Module.

                • Before you RUN the Macro, insure that the Search String Total is available in Range B1:B9 in all the Sheets, from where you are
                  trying to Delete Rows.


                Note:




                • For X = 1 to 10 indicated that MACRO will search TOTAL in 10 Worksheets, which is editable.


                • You may also adjust/alter the Search Range B1:B9 and the String Total as you need.







                share|improve this answer




























                  0












                  0








                  0







                  I would like to suggest a MACRO, which the best and fastest method to Delete all rows from all the Sheets, doesn't contains text TOTAL in specific Column B.



                  Sub Delete_Rows()

                  Dim rng As Range, cell As Range, del As Range
                  Dim sht As Worksheet

                  For X = 1 To 10
                  Set sht = Sheets(X)
                  Set del = Nothing

                  Set rng = Intersect(sht.Range("B1:B9"), sht.UsedRange)

                  For Each cell In rng.Cells

                  If (cell.Value) <> "Total" Then
                  If del Is Nothing Then
                  Set del = cell
                  Else
                  Set del = Union(del, cell)
                  End If
                  End If

                  Next cell

                  If Not del Is Nothing Then del.EntireRow.Delete
                  Next X

                  End Sub


                  How it works:




                  • At any Sheet Press Alt+F11 to open VB Editor then Copy & Paste this Code as Standard Module.

                  • Before you RUN the Macro, insure that the Search String Total is available in Range B1:B9 in all the Sheets, from where you are
                    trying to Delete Rows.


                  Note:




                  • For X = 1 to 10 indicated that MACRO will search TOTAL in 10 Worksheets, which is editable.


                  • You may also adjust/alter the Search Range B1:B9 and the String Total as you need.







                  share|improve this answer















                  I would like to suggest a MACRO, which the best and fastest method to Delete all rows from all the Sheets, doesn't contains text TOTAL in specific Column B.



                  Sub Delete_Rows()

                  Dim rng As Range, cell As Range, del As Range
                  Dim sht As Worksheet

                  For X = 1 To 10
                  Set sht = Sheets(X)
                  Set del = Nothing

                  Set rng = Intersect(sht.Range("B1:B9"), sht.UsedRange)

                  For Each cell In rng.Cells

                  If (cell.Value) <> "Total" Then
                  If del Is Nothing Then
                  Set del = cell
                  Else
                  Set del = Union(del, cell)
                  End If
                  End If

                  Next cell

                  If Not del Is Nothing Then del.EntireRow.Delete
                  Next X

                  End Sub


                  How it works:




                  • At any Sheet Press Alt+F11 to open VB Editor then Copy & Paste this Code as Standard Module.

                  • Before you RUN the Macro, insure that the Search String Total is available in Range B1:B9 in all the Sheets, from where you are
                    trying to Delete Rows.


                  Note:




                  • For X = 1 to 10 indicated that MACRO will search TOTAL in 10 Worksheets, which is editable.


                  • You may also adjust/alter the Search Range B1:B9 and the String Total as you need.








                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 20 '18 at 8:11

























                  answered Dec 20 '18 at 6:17









                  Rajesh SRajesh S

                  1




                  1






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Super User!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1385890%2fif-a-cell-has-a-certain-value-xxx-how-do-i-delete-the-rows-that-dont-have-the%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                      Alcedinidae

                      RAC Tourist Trophy