2

I have a really simple Question: Is there another option to += or -= in VBA?

like:

a += b

instead of:

a = a + b

Thank you very much in advance for your answers...

holyFackel
  • 71
  • 3
  • 11

3 Answers3

4

The compound assignment operators (e.g. +=, -=) do not exist in VBA (which has a similar grammar to VB6, the precursor to VB.net).

You need to fall back to the equivalent a = a + b.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483
1

Not that I'm aware of. This is MDSN link which shows VBA operators and expressions

https://msdn.microsoft.com/en-us/library/a1w3te48.aspx

Jiminy Cricket
  • 1,377
  • 2
  • 15
  • 24
1

Try something like this:

Public Sub Increment(ByRef value_to_increment, Optional l_plus As Long = 1)
    
    value_to_increment = value_to_increment + l_plus

End Sub

Public Sub Decrement(ByRef value_to_decrement, Optional l_minus As Long = 1)
    
    value_to_decrement = value_to_decrement - l_minus

End Sub

This is something that I am using daily. It somehow makes it easier for me. Usage is like this:

Call Increment(lValue)

Example of usage here.

Vityata
  • 42,633
  • 8
  • 55
  • 100