Detecting if the cell contains strikethrough is not working

Ogun999

New Member
Joined
Jun 28, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi,

I am trying to detect which cells contain text that is strikethrough, but my loop is passing over a bunch of cells without detecting the strikethrough text in them.

Here's my Code:

VBA Code:
Private Sub FilterList()

    Dim ws As Worksheet
    Dim rngCheck As Range, rng As Range
    Dim lastRow As Long
    Dim lastCol As Long
   
   
   
 
    Set ws = ThisWorkbook.Sheets(1)
   

    lastCol = ws.UsedRange.Find("reference").column
   
    lastRow = ws.Cells(Rows.Count, 1).End(xlUp).row
   
    Set rng = ws.Range("A1:" & Chr(64 + lastCol) & CStr(lastRow))
   
   
   
    For Each rngCheck In rng.SpecialCells(xlCellTypeVisible)
       
        rngCheck.Select
       
        If rngCheck.Cells.Font.Strikethrough = True Then
          rngCheck.Cells.Interior.Color = RGB(255, 0, 0)
        Else
       
        End If
   
    Next rngCheck
   
   
End Sub
 
Last edited by a moderator:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
I found the answer. I had to check using IsNull. Here's the new code:

VBA Code:
Private Sub FilterList()

Dim ws As Worksheet
Dim rngCheck As Range, rng As Range
Dim lastRow As Long
Dim lastCol As Long




Set ws = ThisWorkbook.Sheets(1)


lastCol = ws.UsedRange.Find("reference").column

lastRow = ws.Cells(Rows.Count, 1).End(xlUp).row

Set rng = ws.Range("A1:" & Chr(64 + lastCol) & CStr(lastRow))



For Each rngCheck In rng.SpecialCells(xlCellTypeVisible)

rngCheck.Select

If IsNull(rngCheck.Cells.Font.Strikethrough) Then
rngCheck.Cells.Interior.Color = RGB(255, 0, 0)
Else

End If

Next rngCheck


End Sub
 
Last edited by a moderator:
Upvote 0
Solution
Are you sure?
If the cell has strikethrough all the way, IsNull returns False.

Rich (BB code):
Private Sub FilterList()

    Dim ws As Worksheet
    Dim rngCheck As Range, rng As Range
    Dim lastRow As Long
    Dim lastCol As Long
    Set ws = ThisWorkbook.Sheets(1)
    
    lastCol = ws.UsedRange.Find("reference").Column
    
    lastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
    
    Set rng = ws.Range("A1", ws.Cells(lastRow, lastCol))
    
    For Each rngCheck In rng.SpecialCells(xlCellTypeVisible)
        
        If rngCheck.Font.Strikethrough Then
            rngCheck.Cells.Interior.Color = RGB(255, 0, 0)
        ElseIf IsNull(rngCheck.Cells.Font.Strikethrough) Then
            rngCheck.Cells.Interior.Color = RGB(255, 0, 0)
        End If
    Next rngCheck


End Sub
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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