ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Checking for cell content (https://www.excelbanter.com/excel-programming/386590-checking-cell-content.html)

danhattan

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

Gary''s Student

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


Dave Peterson

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

danhattan

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


danhattan

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


Dave Peterson

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

danhattan

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



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com