ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA code with and / or statement (https://www.excelbanter.com/excel-programming/405371-vba-code-statement.html)

Steve

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

Nigel[_2_]

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



Dave Peterson

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

Steve

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


All times are GMT +1. The time now is 03:14 PM.

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