samedi 24 août 2019

Simple VBA IF statement problem. Only Else is printed

I am in the first steps of learning VBA and I am facing a problem that seems to be huge. I have a simple if statement that only the else value is printed. Please can anyone help me to understand my mistake? The code is the following:

  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 = 1

Else

rngoff = "smaller"

End If

Next c

End Sub

Also if after the else I replace the code with the: Range("B" & c.Row) = "smaller" it works fine. I cannot understand why I have a problem here.

Regards.

Aucun commentaire:

Enregistrer un commentaire