VBA Code

sandramac
sandramac used Ask the Experts™
on
Hello I have this code below, that is not working properly.  It my current set X37=0 and Y37=2, but it keeps putting the value of "P", when it should be "Y"  Any help would be greatly appreciated

If WS.Range("X37").Value >= 2 And WX.Range("Y37").Value >= 1 Then
    'Purple
    Range("B" & Cells(65536, "B").End(xlUp).Row + 1).Value = "P"
Else
    If WS.Range("X37") >= 1 Then
        'Red
        Range("B" & Cells(65536, "B").End(xlUp).Row + 1).Value = "R"
    Else
        If WS.Range("Y37") >= 1 Then
            'Yellow
            Range("B" & Cells(65536, "B").End(xlUp).Row + 1).Value = "Y"
        End If
    End If
End If
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Mechanical Engineer
Most Valuable Expert 2013
Top Expert 2013
Commented:
Looks like a typo in the first statement with WX.Range("Y37") instead of WS.Range("Y37")

Author

Commented:
Thanks, the simplest things, I been studying so hard on it i overlook such a small thing
byundtMechanical Engineer
Most Valuable Expert 2013
Top Expert 2013

Commented:
sandramac,
Could you post your workbook? From your question, it doesn't seem possible that you would get a value of "P" so we will need to see the code in context with your layout.

Brad
byundtMechanical Engineer
Most Valuable Expert 2013
Top Expert 2013

Commented:
sandramac,
You can avoid typos like this if you use Option Explicit on every module sheet. You can set it up to be inserted automatically using the Tools...Options...Editor menu item (in the VBA Editor) and checking the box for "Require variable declaration"

Brad

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial