I have this myvar="tot01" (as string) i need to add +1 to the last two character and return a new myvar="tot02?
Tks.
NOTE:
the adding value are the ordinal number of the months.
Naturally if i have: myvar="tot12" and add +1 the new result is myvar="tot01"
Add +1 to a string var
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: Add +1 to a string var
Could you not use the current date and append?
Code: Select all
Dim myVar As String
myVar = "tot" & Month(Date)
MsgBox myVar
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- PlatinumLounger
- Posts: 4343
- Joined: 26 Apr 2010, 17:36
Re: Add +1 to a string var
No....Rudi wrote:Could you not use the current date and append?
Code: Select all
Dim myVar As String myVar = "tot" & Month(Date) MsgBox myVar
the append month is dinamic, and not currentd date
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: Add +1 to a string var
Maybe something like this?
Code: Select all
Dim myVar As String
Dim oldVal As String
myVar = "tot01"
oldVal = CInt(Right(myVar, 2)) + 1
If oldVal > 12 Then oldVal = 1
myVar = "tot" & Format(oldVal, "00")
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- 5StarLounger
- Posts: 1098
- Joined: 21 Jan 2011, 16:51
- Location: Florida
Re: Add +1 to a string var
Code: Select all
myVar = Left(myVar, 3) & WorksheetFunction.Choose(CInt(Right(myVar, 2)), "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "01")
PJ in (usually sunny) FL