Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2005

Tip: Looking for answers? Try searching our database.

VB to select previous month

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
crankylemming@aol.com - 23 Jan 2005 13:02 GMT
Hi

I have a workbook that contains 12 sheets named after the months. The
code below is attached to a command button on a form and opens the
worksheet named after the current month (eg, January, if I used the
form today). How can I adapt the code that the button actually looks
for the previous month. I assume it will mean altering the 'Now'
area...? For the sake of argument, all references to CurrMonth would be
'PrevMonth.' Also, 'MonthPick' is the name of the userform.

Private Sub CommandButton1_Click()
Dim CurrMonth As String
CurrMonth = Format(Now, "mmmm")
Sheets(CurrMonth).Select
MonthPick.Hide
End Sub

Thanks in advance

Steve
Doug Robbins - 23 Jan 2005 14:04 GMT
Use Format(DateAdd("m", -1, Now), "mmmm")

Note, that this is a Word newsgroup, not one for Excel.

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

> Hi
>
[quoted text clipped - 16 lines]
>
> Steve
crankylemming@aol.com - 23 Jan 2005 17:21 GMT
Thanks for replying and for your help, Doug.

Sorry, I don't know why I posted it here; in my head I was at the
public.excel group. sorry about that.

Steve
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.