PDA

View Full Version : Solved: Can't get If,Or, to work



Meatball
06-14-2010, 08:45 AM
I have 2 cells that I am checking to see if they say "yes". They use data validation to coose Yes or No. Thet are not in the workbook with the macro. If either of the cells are "yes" I want a cell in the workbook with the macro to say "YES". I have tried several different ways but do not get the correct results.
This is my code
If (Workbooks(CSTRFQ).Sheets("Main Customer Info").Range("B27") = "YES" Or Workbooks(CSTRFQ).Sheets("Main Customer Info").Range("B28") = "YES") Then
With ThisWorkbook.Sheets("Cost Worksheet").Range("K5") = "YES"
End With
End If
What needs to be changed and why?

mdmackillop
06-14-2010, 09:05 AM
Try

With Workbooks(CSTRFQ).Sheets("Main Customer Info")
If UCase(.Range("B27")) = "YES" Or UCase(.Range("B28")) = "YES" Then
ThisWorkbook.Sheets("Cost Worksheet").Range("K5") = "YES"
End If
End With

Meatball
06-14-2010, 09:48 AM
Thanks mdm, It does work but I made a mistake. In the Workbooks(CSTRFQ) It will actually be written as "Yes" in which case your code does not work. I have never seen the case used in macros so I am not sure how to adjust the code.

Simon Lloyd
06-14-2010, 10:18 AM
Try changing = "YES" for =UCASE("YES")

mdmackillop
06-14-2010, 10:19 AM
Hi
Ucase forces whatever is written into upper case to compare with YES. This avoids possible errors in how the data is entered.

Meatball
06-14-2010, 10:43 AM
Simon, that did it, works fine now.
mdm, thanks for that info. I thought I had tried it with the exact way that it was in the Workbooks(CSTRFQ) with no success but perhaps my memory is fading. Anyway, works now.
Thanks to all in the forumn who help those of us lacking sufficiant grey matter.