0

I am pretty new to vba and I don't get why these two statement don't return the same result:

  1. If myValue > 400 Then Range("F" & i).Value = myValue + 10
  2. If myValue > 400 Then myValue = myValue + 10

actually, the first now does its job very well that is to add 10 to the value in Range "F" but the second one just shows it adds 10 to myvalue in "Locals" Window but not in the Range F. There is no error whatsoever picked by VBA! Thank you for your advice

1
  • Why would you expect the second statement to have any affect at all on Fi? Commented Sep 20, 2021 at 20:51

1 Answer 1

1

The difference between your two statements is where you are assigning the value. In the first, you are telling Excel to set the value of the range to myValue + 10. In the second, you are telling Excel to set the value of myValue to myValue + 10. myValue is a variable declared in your VBA. It is not a cell in your spreadsheet.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.