I'm trying to incriment the value in a cell, but despite documentation saying Visual Basic allows the += operator, it's just giving me "Compile error: Expected: expression".
Range("CellName").Value += 1
Is what's breaking, but if I do
Range("CellName") = Range("CellName") + 1
It works fine
Bookmark this question. Show activity on this post. The problem is that != does not work as a function in excel vba.
The <> operator means c. Address Is Not Equal To firstAddress . In a C-style language this would be equivalent to c. Address !=
VBA If OR Operator “If (1 = 1) Or (5 = 0) Then” the if statement uses the OR logical operator to combine two conditions (1 = 1) And (5 = 0). If any of the conditions is true, the code above Else keyword is executed. If both conditions are false, the code below Else keyword is executed.
No, it doesn't exist in VBA.
VB.NET might take +=
(though I'm not even sure about that).
You'll have to use
Range("CellName").Value = Range("CellName").Value+1
A good reference can be found here
An "official" list of VBA-operators can be found in VBA help here:
Help --> Microsoft Visual Basic Help --> Visual Basic for Applications Language Reference --> Visual Basic Language Reference --> Operators --> Arithmetic Operators (online here )
Maybe controversially, but the next advice would have saved me lots of time and headaches:
I'd say it's better to forget everything about VB and focus at VBA, as the two are different languages. People don't mention "Oh, OCaml, APL, PHP or Fortran have increment operators", as it's off-topic if the scope is VBA. In the same way, what VB has or has not is off-topic, and usually it only adds to the confusion because it's resemblance. Better use the MS-Office provided "local" Visual Basic for Applications Language Reference as provided by the help system, or online:
http://msdn.microsoft.com/en-us/library/office/gg264383%28v=office.15%29.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With