Quick question

  • Thread starter Thread starter carlos_ray86
  • Start date Start date
C

carlos_ray86

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
 
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?
 
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
 
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 doesn’t (as far as I’m 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 don’t believe this is what you are trying to
attempt, but I thought I’d let you know, just so you can avoid this situation.
 
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
 
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





- Show quoted text -

This is how I have it right now
If (Cells(18, 3) = Cells(22, 3) And Cells(19, 3) = Cells(23, 3)) And
(Cells(20, 3) = Cells(24, 3) And Cells(19, 3) = Cells(23, 3)) Then
Cells(18, 7) = (Cells(18, 7) + Cells(22, 7))

But I want it to have this
If (Cells(18, 3) = Cells(22, 3) And Cells(19, 3) = Cells(23, 3)) And
(Cells(20, 3) = Cells(24, 3) And Cells(19, 3) = Cells(23, 3)) Then
Cells(18, 7) = (Cells(18, 7) + Cells(22, 7)) And Cells(19, 7) =
(Cells(19, 7) + Cells(23, 7)) And Cells(20, 7) = (Cells(20, 7) +
Cells(24, 7))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top