PC Review


Reply
Thread Tools Rate Thread

Checking for cell content

 
 
=?Utf-8?B?ZGFuaGF0dGFu?=
Guest
Posts: n/a
 
      30th Mar 2007
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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
Guest
Posts: n/a
 
      30th Mar 2007
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

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      31st Mar 2007
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
 
Reply With Quote
 
=?Utf-8?B?ZGFuaGF0dGFu?=
Guest
Posts: n/a
 
      2nd Apr 2007
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

 
Reply With Quote
 
=?Utf-8?B?ZGFuaGF0dGFu?=
Guest
Posts: n/a
 
      2nd Apr 2007
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
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      2nd Apr 2007
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 With Quote
 
=?Utf-8?B?ZGFuaGF0dGFu?=
Guest
Posts: n/a
 
      2nd Apr 2007
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Spell Checking with checking cell notes =?Utf-8?B?amZpdHpwYXQ=?= Microsoft Excel Misc 0 8th Aug 2007 10:26 PM
checking the content of a cell if it starts with certain character =?Utf-8?B?VGltdXI=?= Microsoft Excel Programming 2 1st Aug 2007 01:26 PM
checking file content and move to another dir files with same content Matthieu Microsoft Windows 2000 CMD Promt 2 30th May 2005 07:58 PM
Highlighting cell content based on content of another cell bkarlstrom Microsoft Excel Worksheet Functions 3 4th Dec 2003 02:22 PM
Re: Checking for non-numerical content in a cell Tom Ogilvy Microsoft Excel Programming 0 15th Aug 2003 10:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:15 PM.