View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
nerbe nerbe is offline
external usenet poster
 
Posts: 2
Default MonthName to Integer from Current to Previous Year

I am trying to convert a Month's name to an integer in order to do
trending for the previous six months.

I am taking the string value MonthName() and while looping through a
folder's subfolders am comparing the MonthName to (part of) the
subfolder name. If there is a match, I open the folder and the
workbooks contained therein.

The problem is that I am trying to figure out a way to go back to the
previous year using the following:

'Set Current Date.
dt = DateTime.Date

'Break up the date.
m = DateTime.Month(dt)
d = DateTime.Day(dt)
y = DateTime.Year(dt)

'Prior month's names.
pm1 = MonthName(m - 1)
pm2 = MonthName(m - 2)
pm3 = MonthName(m - 3)
pm4 = MonthName(m - 4)
pm5 = MonthName(m - 5)
pm6 = MonthName(m - 6)
pm7 = MonthName(m - 7)

The current month (April 2006) = 4. When I subtract and finally get to
December 2005, the integer value = 0. November 2005 would theoretically
be -1, October would be -2, September would be -3, and so on.

Does anyone know how I can do this?

Thanks in Advance!