Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Identifying #N/A cells Lee Harris Excel Worksheet Functions 1 November 18th 05 02:57 AM
Excel - Autom. Filter "Empty / Non Empty cells" should come first Rom Excel Discussion (Misc queries) 0 August 10th 05 04:32 PM
How can I convert empty strings to empty cells? Shane Excel Discussion (Misc queries) 2 July 19th 05 12:10 PM
macro to colour empty cells (cells not recognized as empty) Gerben Excel Programming 5 June 30th 05 03:29 PM
Can blank cells created using empty Double-Quotes not be empty?? JohnI in Brisbane Excel Programming 6 September 7th 03 11:22 PM


All times are GMT +1. The time now is 11:44 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"