Delete rows if

Giancar

Board Regular
Joined
Nov 29, 2017
Messages
52
Hi everyone,

Which is the VBA code to delete in the Active worksheet, all the rows that contains in Column D words in strikethrough format?
Weird thing: when I try to find words strikethrough format through "find and replace" button, I have no results.
I am really struggling.

Thank you
 
Give Rick Rothstein's code a go, as that should remove the #N/A anyway
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Code:
Sub Esta()
Dim LR As Long
Dim zxc As Long
Dim Ldate As Date


Ldate = Date
LR = ActiveSheet.Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row


For zxc = LR To 2 Step -1
    If Cells(zxc, 9) < Ldate Then
        Rows(zxc).Delete
    End If
    
    If Cells(zxc, 4) = "#N/A" Then
    Rows(zxc).Delete
    
    End If
Next


End Sub
 
Upvote 0
Give Rick Rothstein's code a go, as that should remove the #N/A anyway

OK, that one is working too! Thank you so much both.

Rick's code is working only on the active sheet. Any suggestion to let it work for following sheets name ("FR", "IT", "ES").
 
Upvote 0
As Rick appears to be offline at the mo, try
Code:
Sub DeleteStrikeThroughRows()

   Dim Ws As Worksheet
   Dim Cell As Range

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
    
   For Each Ws In Sheets(Array("FR", "IT", "ES"))
      For Each Cell In Ws.Range("D1", Ws.Cells(Rows.Count, "D").End(xlUp))
         If Cell.DisplayFormat.Font.Strikethrough Then Cell.Value = "#N/A"
      Next
      On Error Resume Next
      Ws.Columns("D").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
   Next Ws
   
Application.Calculation = xlCalculationAutomatic
End Sub
 
Upvote 0
As Rick appears to be offline at the mo, try
Code:
Sub DeleteStrikeThroughRows()

   Dim Ws As Worksheet
   Dim Cell As Range

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
    
   For Each Ws In Sheets(Array("FR", "IT", "ES"))
      For Each Cell In Ws.Range("D1", Ws.Cells(Rows.Count, "D").End(xlUp))
         If Cell.DisplayFormat.Font.Strikethrough Then Cell.Value = "#N/A"
      Next
      On Error Resume Next
      Ws.Columns("D").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
   Next Ws
   
Application.Calculation = xlCalculationAutomatic
End Sub

It simply perfect. Thank you so much!
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
As Rick appears to be offline at the mo, try
Code:
Sub DeleteStrikeThroughRows()

   Dim Ws As Worksheet
   Dim Cell As Range

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
    
   For Each Ws In Sheets(Array("FR", "IT", "ES"))
      For Each Cell In Ws.Range("D1", Ws.Cells(Rows.Count, "D").End(xlUp))
         If Cell.DisplayFormat.Font.Strikethrough Then Cell.Value = "#N/A"
      Next
      [B][COLOR="#FF0000"]On Error Resume Next[/COLOR][/B]
      Ws.Columns("D").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
   Next Ws
   
Application.Calculation = xlCalculationAutomatic
End Sub
Thanks for jumping in while I was unavailable Fluff. I would make only one change in the code you posted... I would move the On Error Resume Next statement outside of the loop since once it has been enabled, it will remain enabled until turned off with an On Error GoTo 0 statement or until the procedure is exited. And while I did not do so in the code I posted in Message #6 (not sure why), I like to deliberately turn it off once it is no longer needed just in case someone referencing the code decides to add more statements afterward (wouldn't want error handling active for those statements unless the code knew he/she was doing so).
Code:
Sub DeleteStrikeThroughRows()

   Dim Ws As Worksheet
   Dim Cell As Range

   Application.ScreenUpdating = False
   Application.Calculation = xlCalculationManual
    
  [B][COLOR="#FF0000"]On Error Resume Next[/COLOR][/B]
  For Each Ws In Sheets(Array("FR", "IT", "ES"))
      For Each Cell In Ws.Range("D1", Ws.Cells(Rows.Count, "D").End(xlUp))
         If Cell.DisplayFormat.Font.Strikethrough Then Cell.Value = "#N/A"
      Next
      Ws.Columns("D").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
   Next Ws
   [B][COLOR="#FF0000"]On Error GoTo 0[/COLOR][/B]

   Application.Calculation = xlCalculationAutomatic
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,244
Messages
6,170,976
Members
452,372
Latest member
Natalie18

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top