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

4 Leave Cover picture 4 Leave Cover · Jan 1, 2013 · Viewed 162.8k times · Source

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.

Answer

Lord Peter picture Lord Peter · Jan 1, 2013

A common trick is to check like this:

trim(TextBox1.Value & vbnullstring) = vbnullstring

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