Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default VBA code with and / or statement

I cannot get this to run the [ELK] macro when these 3 conditions are
met. It worked until I added the OR statement. I would really like
it to check if the reference cells have numbers in them. Then if NOT
run the ELK macro. If Sheet1.Range("b10").Value < "" Or
Sheet1.Range("b19").Value < "" And Sheet1.Range("b11:aa11").Value =
"" Then [ELK]

Thanks for any help you can provide
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 735
Default VBA code with and / or statement

Think of each logical test returning a TRUE or FALSE

......("b10") < "" is TRUE if NOT equal empty string
......("b19") < "" is TRUE if NOT equal empty string

If you want BOTH to be TRUE then you must AND them, otherwise OR will return
TRUE if either is TRUE.

Finally the last test ...("b11:aa11") is TRUE if the values are = empty
strings; since you want this condition to be TRUE and the previous condition
to also be TRUE you should AND these as well.


--

Regards,
Nigel




"Steve" wrote in message
...
I cannot get this to run the [ELK] macro when these 3 conditions are
met. It worked until I added the OR statement. I would really like
it to check if the reference cells have numbers in them. Then if NOT
run the ELK macro. If Sheet1.Range("b10").Value < "" Or
Sheet1.Range("b19").Value < "" And Sheet1.Range("b11:aa11").Value =
"" Then [ELK]

Thanks for any help you can provide


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default VBA code with and / or statement

If you want to check a multicell range to see if it's empty (no formulas, no
values), you could use:

if application.counta(sheet1.range("b11:aa11")) = 0 then
'all empty

if you wanted to check to see if they were all filled:

if application.counta(sheet1.range("b11:aa11")) _
= sheet1.range("b11:aa11").cells.count then
'all filled

If you wanted to check to see if at least one cell had something (a value or a
formula) in it:

if application.counta(sheet1.range("b11:aa11")) 0 then
'all empty

And if I were you, I'd use some ()'s in my check:

if sheet1.range("b10").value < "" _
or sheet1.range("b19").value < "" _
And application.counta(sheet1.range("b11:a11")) < 0 then

if (sheet1.range("b10").value < "" _
or sheet1.range("b19").value < "") _
And application.counta(sheet1.range("b11:a11")) < 0 then

or

if sheet1.range("b10").value < "" _
or (sheet1.range("b19").value < "" _
And application.counta(sheet1.range("b11:a11")) < 0) then

Your code may work exactly the way you want without the ()'s, but personally,
and/or's without ()'s scare the heck out of me.







Steve wrote:

I cannot get this to run the [ELK] macro when these 3 conditions are
met. It worked until I added the OR statement. I would really like
it to check if the reference cells have numbers in them. Then if NOT
run the ELK macro. If Sheet1.Range("b10").Value < "" Or
Sheet1.Range("b19").Value < "" And Sheet1.Range("b11:aa11").Value =
"" Then [ELK]

Thanks for any help you can provide


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default VBA code with and / or statement

On Jan 31, 10:40*am, Dave Peterson wrote:
If you want to check a multicell range to see if it's empty (no formulas, no
values), you could use:

if application.counta(sheet1.range("b11:aa11")) = 0 then
* 'all empty

if you wanted to check to see if they were all filled:

if application.counta(sheet1.range("b11:aa11")) _
* = sheet1.range("b11:aa11").cells.count then
* 'all filled

If you wanted to check to see if at least one cell had something (a value or a
formula) in it:

if application.counta(sheet1.range("b11:aa11")) 0 then
* 'all empty

And if I were you, I'd use some ()'s in my check:

if sheet1.range("b10").value < "" _
*or sheet1.range("b19").value < "" _
*And application.counta(sheet1.range("b11:a11")) < 0 then

if (sheet1.range("b10").value < "" _
* or sheet1.range("b19").value < "") _
*And application.counta(sheet1.range("b11:a11")) < 0 then

or

if sheet1.range("b10").value < "" _
*or (sheet1.range("b19").value < "" _
*And application.counta(sheet1.range("b11:a11")) < 0) then

Your code may work exactly the way you want without the ()'s, but personally,
and/or's without ()'s scare the heck out of me.

Steve wrote:

I cannot get this to run the [ELK] macro when these 3 conditions are
met. *It worked until I added the OR statement. * I would really like
it to check if the reference cells have numbers in them. Then if NOT
run the ELK macro. * * * If Sheet1.Range("b10").Value < "" Or
Sheet1.Range("b19").Value < "" And Sheet1.Range("b11:aa11").Value =
"" Then [ELK]


Thanks for any help you can provide


--

Dave Peterson


Thanks for the help ! Steve
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
Help Identifying code statement Ayo Excel Discussion (Misc queries) 1 November 29th 07 03:50 AM
If statement to replace #VALUE! code jeannie v Excel Worksheet Functions 8 June 27th 07 03:53 AM
VBA code for IF statement with OR? Dave R. Excel Programming 4 June 27th 05 03:38 PM
Worksheet code if-color-statement Jonsson[_43_] Excel Programming 1 September 29th 04 03:57 PM
Code doesn't go past first IF statement keepITcool Excel Programming 2 July 20th 04 09:48 PM


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