Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


VBA Code

Posted on 2011-09-03
Medium Priority
Last Modified: 2012-05-12
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
    Range("B" & Cells(65536, "B").End(xlUp).Row + 1).Value = "P"
    If WS.Range("X37") >= 1 Then
        Range("B" & Cells(65536, "B").End(xlUp).Row + 1).Value = "R"
        If WS.Range("Y37") >= 1 Then
            Range("B" & Cells(65536, "B").End(xlUp).Row + 1).Value = "Y"
        End If
    End If
End If
Question by:sandramac
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 81

Accepted Solution

byundt earned 2000 total points
ID: 36479280
Looks like a typo in the first statement with WX.Range("Y37") instead of WS.Range("Y37")

Author Comment

ID: 36479282
Thanks, the simplest things, I been studying so hard on it i overlook such a small thing
LVL 81

Expert Comment

ID: 36479285
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.

LVL 81

Expert Comment

ID: 36479288
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"


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question