Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88868

IF logic only follows the Else condition

$
0
0

I have an if statement where only the else value is printed.

The values it selects are in five cells with numbers below 1 and above zero.

It should print one cell offset to the right the word "greater" if the number is greater than 0.5 or equal and smaller of the number is smaller than 0.5.

Sub checkifstatement()

    Dim result As String
    Dim rng As Range

    Set rng = Application.InputBox("Select a range", "Obtain Range Object", Type:=8)

    rngoff = rng.Offset(, 1)

    For Each c In rng
        If c.Value >= 0.5 Then
            rngoff = "greater"    
        Else    
            rngoff = "smaller"
        End If
    Next c

End Sub

If after the else I replace the code with:
Range("B"& c.Row) = "smaller"
it works.


Viewing all articles
Browse latest Browse all 88868