+ Reply to Thread
Results 1 to 13 of 13

How to check for Plus/Minus condition (Macro)

Hybrid View

  1. #1
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,167

    How to check for Plus/Minus condition (Macro)

    With out using Conditional Formatting, how can I check a cells value if it can fall within a range of +\-.002?
    I have this code but it seems to have limitations.

    Range("F6").Select
    Set Min1 = Range("D6")
    Set Max1 = Range("D6")
    a = WorksheetFunction.Min(Min1)
    b = WorksheetFunction.Max(Max1)
    
    With Range("D6")
        If a < "0" Then
            Range("F6").Value = a + "0.0020" '(Difference of)
            Else
                If b > "0.0020" Then
                Range("F6").Value = b - "0.0020" '(Difference of)
        End If
    End If
    If Range("D6").Value < "-0.0020" Then
            Range("F6").ClearContents
            Else
                If Range("D6").Value < "0.0020" Then
                Range("F6").ClearContents
        End If
        End If
    End With
    I am stumbling on how to check the cell to see if it complies to a +\-.002 scenario and if it does, clear the contents of another cell. The above code will clear the cell if the value is positive, but not negative.

    All help is appreciated.
    Regards

    Rick
    Win10, Office 365

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Bit confused from your code on what you are really trying to do, but from your words is this what you are chasing???

    If Range("F6") >= -0.002 And Range("F6") <= 0.002 Then Range("F6").ClearContents

    rylo

  3. #3
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,167
    Peering into my mind is dangerous!

    Here is my scenario, I am attempting to loop thru many rows in two columns to check a condition.
    The condition is a tolerance of +\-.002 of the value in cells from two columns, a range. I am taking the average value of the two cells and testing for conformance of +\-.002 from Zero. If the value is out of tolerance the code does something.

    Conditional Formatting is limited on what I can do, or maybe its me that's limited?

    The .ClearContents can be ignored, I resolved that one. (I feel like such a grown up).

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Rick

    Perhaps an example file showing what you want to happen for a given data set would help clarify.


    rylo

  5. #5
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,167
    See attached Excel file, and please, criticism is accepted, however I have feelings
    Also attached is the macro to run the data. I keep macros in a "personal.xls" file.

    File "Template MPC 3061494-1 Profile .006-.004 JNxxxxx A.txt" needs to be renamed to "Template MPC 3061494-1 Profile .006-.004 JNxxxxx A.xls" and file "Module1_OOT_Profiles_A.txt" needs to be renamed to "Module1_OOT_Profiles_A.bas".
    Attached Files Attached Files
    Last edited by Rick_Stanich; 06-21-2007 at 10:03 AM.

  6. #6
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,167
    I should have zipped both files :shrug:
    Both files in a ZIP format.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1