Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default Calculate Month

I have a table with column headers

8/1/2004 9/1/2004 10/1/2004 ... 3/1/2005

I have to find the column that is 5 months from today and insert a column.
If I run the macro on the 1st of the month or the 31st of the month I should
find the same column.

Thanks,
Denise
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Calculate Month

Dear Denise,

Maybe the following code would help. Choose one of the r.Cells....Insert
lines depending on whether you need the inserted column before or after
the target month

----
Sean
"Just press the off switch, and go to sleep!"

'''''''''''''''''''''''''''''''''''''''''''''''''' '
'''''''''''''''''''''''''''''''''''''''''''''''''' '
Sub FindAndInsert()
Dim d As Long, r As Range, i As Long

' assuming the months are in the first row of our worksheet
Set r = ActiveSheet.Rows(1)

' first get the current date PLUS 5 months
d = Now()
d = DateSerial(Year(d), Month(d) + 5, 1)

' use the MATCH() function to find our valid month
' if no match if found then just quit
On Error GoTo Exit_proc
i = Application.WorksheetFunction.Match(d, r, 0)

' either insert a column BEFORE the one found
r.Cells(1, i).EntireColumn.Insert

' or insert a column AFTER the one found
'r.Cells(1, i + 1).EntireColumn.Insert

Exit_proc:
Exit Sub
End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''' '
'''''''''''''''''''''''''''''''''''''''''''''''''' '

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
formula to calculate month-month User Excel Discussion (Misc queries) 2 February 16th 10 10:28 AM
calculate month RJ Excel Worksheet Functions 9 September 25th 08 03:06 PM
Calculate days in a month N Harkawat Excel Worksheet Functions 2 September 16th 08 08:46 PM
calculate Age Year Month & day shailendra joshi Excel Discussion (Misc queries) 3 September 6th 08 03:33 PM
Calculate the first day of the month for the current month? April S. Excel Discussion (Misc queries) 5 July 27th 05 08:53 PM


All times are GMT +1. The time now is 02:49 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"