Search code examples
excelvbaspace

EXCEL VBA Check if entry is empty or not 'space'


Note. Check if the TextBox1 is empty is easy by using TextBox1.Value = "".

But the problem is when the user hit the spacebar, TextBox1 will still recognize it as a value. In such case, my data will appear as an empty cell with 1 space inside. So my question is, is there any method to check TextBox1.value for empty and also not consist of space whether there are 1 or more space? Million thanks to all.


Solution

  • A common trick is to check like this:

    trim(TextBox1.Value & vbnullstring) = vbnullstring
    

    this will work for spaces, empty strings, and genuine null values