Link to home
Start Free TrialLog in
Avatar of salibes
salibes

asked on

Incrementing character and month type

how do I increase the character and month type value by one letter and one month, respectivley.

Example...

Char = "A"
Char = Char +1 ' set char = "B" (this is what i want)

Month = "7/1/2002"
Month = Month + 1 month should set it to "8/1/2002", and loop through to a new year at month 13...

how could I code this in VB?
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Char = "A"
Char = Chr$(Asc(Char) + 1)

Month = "7/1/2002"
Month = DateAdd("m", 1, CDate(Month))

Anthony
angelIII beat me to it.

Anthony
Avatar of salibes
salibes

ASKER

Thank you... is there a way to go from z to AA, I will award angel the points but thats perkins also
Not really, unless you code a loop with some conditions:

dim char1 as string
dim char2 as string

char1 = " "
char2 = "A"

do
  if char2 = "Z" then
    char1 = chr(asc(char1)+1)
    char2 = "A"
  else
    char2 = chr(asc(char2)+1)
  endif
  debug.print trim(char1 & char2)
loop until char2 = "Z" and char1 = "Z"

CHeers
It appears that you're trying to navigate through an Excel spreadsheet's columns.  There are other ways around that.  Have you tried using the .Cells(Row,Col) variation?  Using that, you only need the number of the column, not the numerical name.  Therefore, column "A" is 1, "B" is 2, ..."Z" is 26, "AA" is 27, ..."AZ" is 52, "BA" is 53 etc.

If you need more info, check the help files or let me know.
Avatar of salibes

ASKER

Thanks rspahitz  also, you were very helpful for my second question... sorry i cnat split points
Well, glad to help anyway.
Avatar of salibes

ASKER

when I do Range.Cells(2, 9).Value it says argument not optional, it highligts "Range", any ideas?
Omit the "Range" portion and just use:

Cells(2, 9).Value