0

Based on this spreadsheet,

enter image description here

Running this line of code will return False

MsgBox IsEmpty(Trim(ThisWorkbook.ActiveSheet.Cells(31, 1)))

But running

=IsBlank(A31) 

will return True

Pherdindy
  • 1,168
  • 7
  • 23
  • 52
  • 3
    Empty cells are empty and blank cells can appear empty although they aren't due to them containing a formula returning empty text. – braX Dec 02 '19 at 08:35

1 Answers1

2

It's because you use Trim.

Excel's IsBlank is very restrictive and will only ever give True if the cell is completely empty (not even has a formula that returns empty result). So if that returns True, IsEmpty on the cell's value should also return True.

But what IsEmpty(cell) actually does is detecting whether the cell's .Value contains the special value Variant/Empty. The raw cell value does indeed contain it, and IsEmpty(ThisWorkbook.ActiveSheet.Cells(31, 1)) would return True, but Trim() turns the Variant/Empty into a Variant/String, and a string is never IsEmpty, even when it's zero length.

If for you "empty" means "contains zero length content", then you should check for Len(Trim(ThisWorkbook.ActiveSheet.Cells(31, 1))) = 0.

GSerg
  • 76,472
  • 17
  • 159
  • 346