Still learning

  • Thread starter Thread starter ceplane
  • Start date Start date
C

ceplane

How do I put this formula into code?

=IF((A9=G3)+OR(A9=H3)+AND(A9<H3),L3,"")

Thank yo
 
Code
-------------------
If Range("A9").Value = Range("G3").Value Or _
Range("A9").Value = Range("H3").Value And _
Range("A9").Value < Range("H3").Value Then
Range("A1").Value = Range("L3").Value
Else
Range("A1").Value = ""
End I
 
The OR and AND in the formula do nothing since they only have a single
argument.

The plus connective is equivalent to OR

Your code would be:

If Range("A9").Value = Range("G3").Value Or _
Range("A9").Value = Range("H3").Value Or _
Range("A9").Value < Range("H3").Value Then
Range("A1").Value = Range("L3").Value
Else
Range("A1").Value = ""
End If

or
If Range("A9").Value = Range("G3").Value Or _
Range("A9").Value <= Range("H3").Value Then
Range("A1").Value = Range("L3").Value
Else
Range("A1").Value = ""
End If

Now that says nothing about the intent of the original poster who may have
posted an erroneous formula (certianly looks to be).
 
I didn't think I had an erroneous formula. I maybe barking up the wron
tree though. I have 100+ rows, dates in 1st column and based on
match between two dates (two cells) the sum of another cell is entere
in the next column, same row. The formula appeared to work until
reopened the workbook and entered more data. Then the first entry wa
replaced. I felt that if I could put the formula in code it woul
solve my problem. I also thought of Vlook. But again I don'
understand code enough to translate. ?????

Thank
 
there is no difference between

=IF((A9=G3)+OR(A9=H3)+AND(A9<H3),L3,"")

and

=IF((A9=G3)+(A9=H3)+(A9<H3),L3,"")

which says if A9 = G3 or A9 = H3 or A9 < H3 then show L3 else show nothing

or even

=IF((A9=G3)+(A9<=H3),L3,"")

also equivalent to

=IF(Or(A9=G3,A9<=H3),L3,"")

If the OR or AND was supposed to have some meaning, then the formula does
not perform as expected.

if you want A9 to match H3 and G3 then

=IF(AND(A9=G3,A9=H3),L3,"")

If you want A9 to match g3 and be less than or equal to H3

=IF(AND(A9=G3,A9<=H3),L3,"")

If you don't want the results of the formula to change after entry

set rng = Range(Cells(1,2),Cells(rows.count,2).End(xlup))
rng.Formula = rng.Value

Removes the formula and replaces them with the values they were displaying.
 

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