Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / January 2008

Tip: Looking for answers? Try searching our database.

how to convert a cell value into boolean

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cghersi - 03 Jan 2008 16:05 GMT
Hi.

I'm facing up the following issue: in a sheet there's a matrix of
boolean values (TRUE, FALSE) that I have to read/write via vba.

Sometimes (not deterministically), a statement like:

if Cells(2,4).value then
' do something
else
' do something else
end if

returns a type mismatch because it reads the cell as string and not as
boolean (obviously in Cells(2,4) there is a TRUE value).

This behaviour doesn't always happen, only sometimes (non
deterministically, as previously said).

The solution that I've thought to is to force the format of the cell
as boolean, bu I don't know how.

Any ideas? or anything else?

unfortunately the application must be language independent, so I
cannot use a comparison like

if Cells(2,4).value = "TRUE" then ...

Moreover, I would like not ot use parsing function (like CBool)
because the performance get worse and worse, and this is another
issue...

thank u very much

bye

CRI
Jim Cone - 03 Jan 2008 16:40 GMT
You could try...
If Trim(Cells(2,4).Value) = True Then
Signature

Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)

"cghersi"
wrote in message
Hi.

I'm facing up the following issue: in a sheet there's a matrix of
boolean values (TRUE, FALSE) that I have to read/write via vba.

Sometimes (not deterministically), a statement like:

if Cells(2,4).value then
' do something
else
' do something else
end if

returns a type mismatch because it reads the cell as string and not as
boolean (obviously in Cells(2,4) there is a TRUE value).
This behaviour doesn't always happen, only sometimes (non
deterministically, as previously said).
The solution that I've thought to is to force the format of the cell
as boolean, bu I don't know how.
Any ideas? or anything else?
unfortunately the application must be language independent, so I
cannot use a comparison like
if Cells(2,4).value = "TRUE" then ...
Moreover, I would like not ot use parsing function (like CBool)
because the performance get worse and worse, and this is another
issue...
thank u very much
bye
CRI

Dave Peterson - 03 Jan 2008 16:53 GMT
You sure that there's a value of TRUE in that cell?

I've seen the mismatch error when there was an error in that cell:

with activesheet.cells(2,4)
 if iserror(.value) then
   msgbox "it's an error"
 else
    if .value = true then
       msgbox "It's true"
    else
       msgbox "it's not true"
    end if
 end if
end with

> Hi.
>
[quoted text clipped - 34 lines]
>
> CRI

Signature

Dave Peterson

ilia - 03 Jan 2008 19:38 GMT
Try this:

MsgBox CBool(Cells(2,4).Value)

> Hi.
>
[quoted text clipped - 34 lines]
>
> CRI
cghersi - 14 Jan 2008 10:26 GMT
> Try this:
>
[quoted text clipped - 40 lines]
>
> - Mostra testo tra virgolette -

Hi, thank u to all for the replies.

what about the performance of CBool operator?
what's the difference between a simple check:
   if Cells(2,4).value then
and a CBool check like:
   if CBool(Cells(2,4).value) then

thank u

CRI
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.