IsEmpty function not working in Macro
well... frankly, it means the cells you're working with aren't empty. i suggest you double-check that you're testing the cells you think you are.
set a breakpoint after the line "ActiveCell.Offset(0, 1).Select", then hit CTRL+G when the program breaks to bring up the Immediate Window. in that window, type "? ActiveCell.Address" and hit enter to see what cell you're actually looking at, then verify that it's empty onscreen. additionally, you can type "? IsEmpty(ActiveCell.Value)" or just "? ActiveCell.Value" and see what pops up.
hope this helps - happy debugging!
More on reddit.comIsEmpty Function VBA
VBA need help for isempty function
VBA If Not IsEmpty
Videos
I have multiple lines in my macro where I am checking to see if the current cell is empty or not. One of the lines works great. Two do not. I have copied the code for the two that don't from the one that does and it still isn't working. I've been stepping through the code line by line and I watch it not execute and I can't figure out where I'm going wrong. I also tried the Googles but no results there seemed to match my problem. Basically, regardless of the value in the active cells, the code always skips straight to "Else", even if one cell is empty and one is not. I have copied this exact code into a separate macro that was just this code and it worked fine. Why on earth would it not work here?
I Trim the cell to get rid of any potential whitespace characters. I'm sure there are more efficient ways to do this but, alas, I am not a code wizard yet. Bool1 and Bool2 are created and initialized to False earlier in the code. Also, the line that works uses the exact same IF statement setup, just with different values. Any help would be greatly appreciated.
Here is the snippet
ActiveCell.Value = Trim(ActiveCell.Value)
If IsEmpty(ActiveCell.Value) = True Then
'cell empty
bool1 = False
Else
'cell has x
bool1 = True
End If
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Trim(ActiveCell.Value)
If IsEmpty(ActiveCell.Value) = True Then
'cell empty
bool2 = False
Else
'cell has x
bool2 = True
End If
well... frankly, it means the cells you're working with aren't empty. i suggest you double-check that you're testing the cells you think you are.
set a breakpoint after the line "ActiveCell.Offset(0, 1).Select", then hit CTRL+G when the program breaks to bring up the Immediate Window. in that window, type "? ActiveCell.Address" and hit enter to see what cell you're actually looking at, then verify that it's empty onscreen. additionally, you can type "? IsEmpty(ActiveCell.Value)" or just "? ActiveCell.Value" and see what pops up.
hope this helps - happy debugging!
What is the point if IsEmpty then? I always used = “” because i never knew about IsEmpty. However, if i had known about it i could see myself trying to use it like OP. What would be a practical use case of the function?