Akshay Patel
Akshay Patel

Reputation: 1

Obtain the last digit of a number contained in a variable

I'm writing a script in VBA and have a quick question that I can't solve at the moment. One of the variables , 'newAmend', contains an integer value. This value could be any number from 1-1500. What I want to do is find out the last digit (right-most digit) of the variable and store that number into another variable.

So if newAmend = 579, I'd want to store the value of 9 into a new variable.

Does anyone have any suggestions. I can't specifically recall how to parse through a variable / unsure if VBA supports it.

Upvotes: 0

Views: 438

Answers (1)

Scott Craner
Scott Craner

Reputation: 152585

Use Mod:

Dim lastnum as integer
lastnum = newAmend Mod 10

Upvotes: 1

Related Questions