I have a 2003 Excel Sheet in that before it prints its does some checking of data for missing data (user form)
I have a cell that when I edit it (F2), view it, or msgbox it, its emtpy... however in my code "IsEmpty" is thinks its not emtpy. If I edit the cell and just press delete then it treats it as emtpy as nothing was in the cell and the cursor doesn't move left when I "deleted" the text).
What is causing this and how can I prevent or check for these mysterious characters? I would like to remove them so I can truly check if the cell is empty.
Thank you.
Microsoft Excel
Last Comment
dlmille
8/22/2022 - Mon
Kyle Abrahams
Most likely a space. EG: " "
Try the trim function in your code, if there is no trim: Replace(" ", "") (eg: replace blank spaces with nothing). Note: this is for the initial check only of IsEmpty.
Martin Liss
It probably contains a Tab or some other unprintable character.
kgerb
It might be an empty string (""). To test you can try these in the immediate window.
?isempty(Range("A1"))
?Range("A1") = vbnullstring
For a blank string IsEmpty will return false and vbnullstring will return true.
You can try that in the immediate window if you want, then type the following:
debug.print Len(Range("I19"))
You SHOULD get a zero length string after all that...
This should trim multiple spaces, remove the nonprintables (most) and the chr(160) nonprintable. Likely this gets the high end if not all of the nonprintable space you'd be dealing with.
PS - the IsEmpty() function by definition identifies whether a variant variable has been initialized. Its not for testing cell ranges, but to advise if a variant variable is holding some type of data.
Select the IsEmpty word in your code and hit F1 for more help on the topic.
Dave
Martin Liss
Nice code dlmille.
thandel
ASKER
Thank you... however this doesn't seem to be "cleaning" the cell. If I enter a space.... it removes the space but Isempty still thinks its not empty. After running Replace(WorksheetFunction.Clean(WorksheetFunction.Trim(Range("I19").Value)), Chr(160), vbNullString) what is left in the cell to still think there is something in the cell?
Try the trim function in your code, if there is no trim: Replace(" ", "") (eg: replace blank spaces with nothing). Note: this is for the initial check only of IsEmpty.