Incrementing a variable by 1

S

skulkrinbait

Apologies for the simple question, but I can't find the answer by
searching the net.

In PHP you can increment a variable by 1 thus:

$var++;

In some forms of BASIC it's:

var +=1

How do you incremenet a variable by 1 in VBA other than:

iVar = iVar + 1

Is there simpler way?

Thanks.
 
G

Guest

iVar = iVar + 1 doesn't seem particularly onerous to me but another way is a
For - Next loop where the variable is increased by 1 when the next is
executed.
 
S

skulkrinbait

iVar = iVar + 1 doesn't seem particularly onerous to me but another way is a
For - Next loop where the variable is increased by 1 when the next is
executed.











- Show quoted text -

Thanks, I was wondering as some of my variable names are quite long so
if you could do it using var ++ or something it would save me a second
or two each time, I must be getting lazy.
 
N

Norman Jones

Hi Sskulkrinbait,

'-----------------
Thanks, I was wondering as some of my variable names are quite long so
if you could do it using var ++ or something it would save me a second
or two each time, I must be getting lazy.
'-----------------

You could autocomplete the long variable name
using Ctrl_Shift ...
 
G

Guest

Norman Jones said:
Hi Sskulkrinbait,

'-----------------
Thanks, I was wondering as some of my variable names are quite long so
if you could do it using var ++ or something it would save me a second
or two each time, I must be getting lazy.
'-----------------

You could autocomplete the long variable name
using Ctrl_Shift ...
It is not Ctrl+Shift
The Autocomplete Word option is Ctrl+Space
 
N

Norman Jones

Hi Ruben,
It is not Ctrl+Shift
The Autocomplete Word option is Ctrl+Space



Indeed! I intended Spacebar but somehow wrote Shift!

Thankyou for the correction.
 
D

Dana DeLouis

I was wondering as some of my variable names are quite long so

Hi. This is in my Library of routines. I shortened the name to "Inc" to
represent the "Increment" function.

Function Inc(ByRef n)
'// Increment by +1
n = n + 1
End Function

Sub Test()
Dim ALongVariableName
ALongVariableName = 6
Inc ALongVariableName
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top