0
Function HasStrike(Rng as Range) As Boolean
HasStrike = Rng.Font.Strikethrough
End Function

I am using a custom function to see if a column has a strikethrough. If the column has a strikethrough, it returns a boolean and I delete the row. However, I am getting a #VALUE error. The column I am checking only has the word "MASS" in it. Not sure what's going on.

User Screenshot

Chrismas007
  • 6,085
  • 4
  • 24
  • 47
kmiao91
  • 303
  • 4
  • 11
  • 22

1 Answers1

0

Your function will return #VALUE if the cell content has mixed formatting: some text is struck out and some not.

Select one of the "problem" input cells and go to the "Format Cells" >> Font tab. Is "Strikethrough" checked or does it look like below? That would indicate mixed formatting.

enter image description here

Try this maybe:

Function HasStrike(Rng As Range) As Boolean
    Dim v
    Application.Volatile '<< EDIT: added this
    On Error Resume Next
    v = Rng.Font.Strikethrough
    On Error GoTo 0
    HasStrike = v Or IsNull(v)
End Function
Tim Williams
  • 154,628
  • 8
  • 97
  • 125
  • Hmmm - It seems to have half worked. The function returns Boolean but the boolean isn't right. I'm getting false for cells that do have strikethroughs – kmiao91 Feb 27 '15 at 18:26
  • 1
    You have to make sure to recalculate the function - it may not trigger a recalculation if you just change the formatting (or the VBA code for the function), since you didn't change the *value* of the input cell. Maybe add `Application.Volatile` at the top of the function. – Tim Williams Feb 27 '15 at 20:37