ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Quick question (https://www.excelbanter.com/excel-programming/393974-quick-question.html)

[email protected]

Quick question
 
for an If..Then statement you can do If "A1=B1" and "B1=C1" then
A1=C1. But is there a connecting word(AND) that can be done in the
then part. such as......If (A1=B1) and (B1=C1) then (A1=C1) And
(A1+3=D1)

I know the syntacs aren't correct its an example to get the point
across. Thanks


Tom Ogilvy

Quick question
 
If A1=B1 and B1=C1 then
A1=C1
D1 = A1+3
End if

A1 + 3 can't equal D1 unless you are testing if they do?

--
Regards,
Tom Ogilvy


" wrote:

for an If..Then statement you can do If "A1=B1" and "B1=C1" then
A1=C1. But is there a connecting word(AND) that can be done in the
then part. such as......If (A1=B1) and (B1=C1) then (A1=C1) And
(A1+3=D1)

I know the syntacs aren't correct its an example to get the point
across. Thanks



XP

Quick question
 


" wrote:

for an If..Then statement you can do If "A1=B1" and "B1=C1" then
A1=C1. But is there a connecting word(AND) that can be done in the
then part. such as......If (A1=B1) and (B1=C1) then (A1=C1) And
(A1+3=D1)

I know the syntacs aren't correct its an example to get the point
across. Thanks



SeanC UK[_3_]

Quick question
 
Carlos,

I would suggest you try to make the syntax as realistic as possible. As Tom
says, what you have written would clearly run into problems. Also, it is hard
to tell (for me at least) whether you are talking about writing the code as a
worksheet function or within a VBA module

If you are working in a VBA module then you can perform multiple tasks based
on the results of your comparison:

If (A1 = B1) And (B1=C1) Then
Do this
Do this too
And this
ElseIf (A1 = B2)
Do this
And this
Else
Do this
End If

If you are working with worksheet formulas then no, because you have:

=IF(AND(A1=B1,B1=C1), C2, C3)

So the cell you type the formula in will result in the value of C2 if the
condition is true, and C3 if the condition is false.

A worksheet function doesnt (as far as Im aware) allow you to alter
another cell directly, it simply gives the result of the formula you type in
that cell.

However, if you type

=IF(AND(A1=B1,B1=C1),C2=5,C3=4))

Then if A1 = B1 and B1 = C1 then the true part of the result is looked at
(C2=5) and if cell C2 does equal 5 the cell containing the formula will
result in €śTrue€ť, whereas if cell C2 does not equal 5 then the cell
containing the formula will result in €śFalse€ť. Also, if the original
condition is False, then C3 = 4 is compared and the cell containing the
formula will again result in either True or False. Therefore, there are
numerous ways of getting the same result, and for most purposes you will not
know whether conditions have been met or not (or which conditions at least).
It would probably be better to keep all the conditional statements in the 1st
part of the function. Anyway, I dont believe this is what you are trying to
attempt, but I thought Id let you know, just so you can avoid this situation.





" wrote:

for an If..Then statement you can do If "A1=B1" and "B1=C1" then
A1=C1. But is there a connecting word(AND) that can be done in the
then part. such as......If (A1=B1) and (B1=C1) then (A1=C1) And
(A1+3=D1)

I know the syntacs aren't correct its an example to get the point
across. Thanks



[email protected]

Quick question
 
There is no reason to do an assignment of A1=C1 since by logic this is
already true. So I think we need a better explanation of what they
are trying to accomplish.

Peter Richardson

On Jul 23, 3:22 pm, Tom Ogilvy
wrote:
If A1=B1 and B1=C1 then
A1=C1
D1 = A1+3
End if

A1 + 3 can't equal D1 unless you are testing if they do?

--
Regards,
Tom Ogilvy



" wrote:
for an If..Then statement you can do If "A1=B1" and "B1=C1" then
A1=C1. But is there a connecting word(AND) that can be done in the
then part. such as......If (A1=B1) and (B1=C1) then (A1=C1) And
(A1+3=D1)


I know the syntacs aren't correct its an example to get the point
across. Thanks- Hide quoted text -


- Show quoted text -





All times are GMT +1. The time now is 05:16 PM.

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