Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Checking for cell content

I need to know if a cell is empty so my code can paste into it if so. If I
were just entering a formula into a worksheet I'd just use COUNT or COUNTA.
But I'm not sure what the equivalent check in VBA is. Unfortunately, my data
will at times include zeros so checking for 0 isn't working either.

If anyone can help me, it's very much appreciated.

Dan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Checking for cell content

Sub routine()
If IsEmpty(Selection) Then
MsgBox ("Really empty")
End If
End Sub

--
Gary's Student


"danhattan" wrote:

I need to know if a cell is empty so my code can paste into it if so. If I
were just entering a formula into a worksheet I'd just use COUNT or COUNTA.
But I'm not sure what the equivalent check in VBA is. Unfortunately, my data
will at times include zeros so checking for 0 isn't working either.

If anyone can help me, it's very much appreciated.

Dan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Checking for cell content

For one cell:
if isempty(yourrangehere.value) then

If it's multiple cells:
if application.counta(yourrangehere) = 0 then

danhattan wrote:

I need to know if a cell is empty so my code can paste into it if so. If I
were just entering a formula into a worksheet I'd just use COUNT or COUNTA.
But I'm not sure what the equivalent check in VBA is. Unfortunately, my data
will at times include zeros so checking for 0 isn't working either.

If anyone can help me, it's very much appreciated.

Dan


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Checking for cell content

That worked perfectly. Thanks very much for the help.

"Gary''s Student" wrote:

Sub routine()
If IsEmpty(Selection) Then
MsgBox ("Really empty")
End If
End Sub

--
Gary's Student


"danhattan" wrote:

I need to know if a cell is empty so my code can paste into it if so. If I
were just entering a formula into a worksheet I'd just use COUNT or COUNTA.
But I'm not sure what the equivalent check in VBA is. Unfortunately, my data
will at times include zeros so checking for 0 isn't working either.

If anyone can help me, it's very much appreciated.

Dan

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Checking for cell content

That worked very well, so I thank you for that, but wonder if you might be
able to clear up another bit of confusion.

After I made the post, I wondered if activecell.value = true might be a good
test. Whipped it up in a test spreadsheet and it worked. But when I put it
into the real spreadsheet this morning, it didn't recognize 0's as cell
content.

Is there a simple explanation for why that would be? If you have the time to
answer, again, much appreciated.

"Dave Peterson" wrote:

For one cell:
if isempty(yourrangehere.value) then

If it's multiple cells:
if application.counta(yourrangehere) = 0 then

danhattan wrote:

I need to know if a cell is empty so my code can paste into it if so. If I
were just entering a formula into a worksheet I'd just use COUNT or COUNTA.
But I'm not sure what the equivalent check in VBA is. Unfortunately, my data
will at times include zeros so checking for 0 isn't working either.

If anyone can help me, it's very much appreciated.

Dan


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Checking for cell content

VBA sees True as -1.
and every other value as false.

I'm not sure what was in your cell to get it to work, though.



danhattan wrote:

That worked very well, so I thank you for that, but wonder if you might be
able to clear up another bit of confusion.

After I made the post, I wondered if activecell.value = true might be a good
test. Whipped it up in a test spreadsheet and it worked. But when I put it
into the real spreadsheet this morning, it didn't recognize 0's as cell
content.

Is there a simple explanation for why that would be? If you have the time to
answer, again, much appreciated.

"Dave Peterson" wrote:

For one cell:
if isempty(yourrangehere.value) then

If it's multiple cells:
if application.counta(yourrangehere) = 0 then

danhattan wrote:

I need to know if a cell is empty so my code can paste into it if so. If I
were just entering a formula into a worksheet I'd just use COUNT or COUNTA.
But I'm not sure what the equivalent check in VBA is. Unfortunately, my data
will at times include zeros so checking for 0 isn't working either.

If anyone can help me, it's very much appreciated.

Dan


--

Dave Peterson


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Checking for cell content

Well, my test code was just a simple If ActiveCell.Value = True, and if so,
msgbox Something In There, and if not msgbox Nothing There. When I put a
number in the cell, I got the first msgbox, and when I deleted it, got the
latter. Having never used that method before, deduced that it would recognize
any cell that had content.

However, when I then applied it to a true range of data, it considered cells
with a zero in it to be empty and wrote over them rather than skipping past
to the next truly empty cell.

Thanks for the reply by the way. It helps to know that I wasn't using that
piece of code correctly.

"Dave Peterson" wrote:

VBA sees True as -1.
and every other value as false.

I'm not sure what was in your cell to get it to work, though.



danhattan wrote:

That worked very well, so I thank you for that, but wonder if you might be
able to clear up another bit of confusion.

After I made the post, I wondered if activecell.value = true might be a good
test. Whipped it up in a test spreadsheet and it worked. But when I put it
into the real spreadsheet this morning, it didn't recognize 0's as cell
content.

Is there a simple explanation for why that would be? If you have the time to
answer, again, much appreciated.

"Dave Peterson" wrote:

For one cell:
if isempty(yourrangehere.value) then

If it's multiple cells:
if application.counta(yourrangehere) = 0 then

danhattan wrote:

I need to know if a cell is empty so my code can paste into it if so. If I
were just entering a formula into a worksheet I'd just use COUNT or COUNTA.
But I'm not sure what the equivalent check in VBA is. Unfortunately, my data
will at times include zeros so checking for 0 isn't working either.

If anyone can help me, it's very much appreciated.

Dan

--

Dave Peterson


--

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
Spell Checking with checking cell notes jfitzpat Excel Discussion (Misc queries) 0 August 8th 07 10:26 PM
copy comment content to cell content as data not as comment Lilach Excel Discussion (Misc queries) 2 June 21st 07 12:28 PM
Checking range of cells for entry then checking for total Barb Reinhardt Excel Programming 1 October 13th 06 02:47 PM
Checking and merging content from several worksheets KellyK Excel Programming 0 October 19th 05 11:30 PM
Checking for non-numerical content in a cell Tom Ogilvy Excel Programming 0 August 15th 03 10:54 PM


All times are GMT +1. The time now is 10:40 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"