Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Identifying empty cells in VBA
Hi,
I'm looking for a foolproof way of identify empty cells within VBA code. For example I've written code that extracts the first two digits from a postcode but the code fails when I encounter an empty cell. I've tried building in If statements with isempty, isblank and Null and " " but its doesn't seem to work 100% of the time. Any suggestions would be greatly appreciated. Regards David |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Identifying empty cells in VBA
Try LEN
If Len(cell) = 0 Then ... -- HTH RP (remove nothere from the email address if mailing direct) "David" wrote in message ... Hi, I'm looking for a foolproof way of identify empty cells within VBA code. For example I've written code that extracts the first two digits from a postcode but the code fails when I encounter an empty cell. I've tried building in If statements with isempty, isblank and Null and " " but its doesn't seem to work 100% of the time. Any suggestions would be greatly appreciated. Regards David |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Identifying empty cells in VBA
David,
Try using the Trim function. If Trim(Range(CurrentCell)) = "" then end if It's worked well for me. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Identifying empty cells in VBA
If the cell is really empty (no formulas, too!):
if isempty(mycell) then '''' If the cell contains a formula that returns "": if mycell.value = "" then If you really use a spacebar to "empty" a cell: if trim(mycell.value) = "" then (Using a spacebar to make the cell look empty can cause lots of trouble. I think it's better to just hit the delete key on the keyboard (or Edit|Clear|Contents) David wrote: Hi, I'm looking for a foolproof way of identify empty cells within VBA code. For example I've written code that extracts the first two digits from a postcode but the code fails when I encounter an empty cell. I've tried building in If statements with isempty, isblank and Null and " " but its doesn't seem to work 100% of the time. Any suggestions would be greatly appreciated. Regards David -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Identifying #N/A cells | Excel Worksheet Functions | |||
Excel - Autom. Filter "Empty / Non Empty cells" should come first | Excel Discussion (Misc queries) | |||
How can I convert empty strings to empty cells? | Excel Discussion (Misc queries) | |||
macro to colour empty cells (cells not recognized as empty) | Excel Programming | |||
Can blank cells created using empty Double-Quotes not be empty?? | Excel Programming |