+ Reply to Thread
Results 1 to 5 of 5

UserForm to select current month or earlier

  1. #1
    Steve
    Guest

    UserForm to select current month or earlier

    Hi

    I'm wondering if this can be done...?

    I have a workbook which contains, among others, 12 sheets named after
    the months January through to December.

    I would like to have a UserForm which gives a buttonclick choice:
    Current Month or Last Month. Is it possible to have the each button
    open up the correct month, ie Current Month would open ("January") and
    Last Month open ("December")? If so, does anyone have any suggestions
    as to how?

    TIA

    Steve


  2. #2
    Registered User
    Join Date
    01-22-2004
    Location
    UK
    Posts
    27
    I would suggest you create to command buttons on a userform and then use the following for the each button:

    Private Sub CommandButton1_Click()
    Dim thisMonth As Integer
    Dim txtCurMonth As String

    thisMonth = Month(Now())
    txtCurMonth = MonthName(thisMonth)
    ThisWorkbook.Worksheets(txtCurMonth).Select

    End Sub

    Private Sub CommandButton2_Click()
    Dim lastDate As Date
    Dim lastMonth As Integer
    Dim txtLastMonth As String

    lastDate = DateAdd("m", -1, Now())
    lastMonth = Month(lastDate)
    txtLastMonth = MonthName(lastMonth)
    ThisWorkbook.Worksheets(txtLastMonth).Select

    End Sub

    This should work, let me know

  3. #3
    Jason Morin
    Guest

    Re: UserForm to select current month or earlier

    Instructions on building a User Form is difficult, but not
    for an InputBox. It's not as pretty, but here's something
    to start with:

    Sub SelectMonth()
    Dim sMonth As String
    Dim CurrMonth As String
    sMonth = InputBox("1 for current month," & _
    " 2 for last month")
    If sMonth = "" Then Exit Sub
    Select Case sMonth
    Case 1
    CurrMonth = Format(Now, "mmmm")
    Sheets(CurrMonth).Select
    Case 2
    Sheets("December").Select
    Case Else
    MsgBox ("Please insert 1 or 2!")
    End Select
    End Sub

    ---
    Insert this into a standard module.

    HTH
    Jason
    Atlanta, GA

    >-----Original Message-----
    >Hi
    >
    >I'm wondering if this can be done...?
    >
    >I have a workbook which contains, among others, 12 sheets

    named after
    >the months January through to December.
    >
    >I would like to have a UserForm which gives a buttonclick

    choice:
    >Current Month or Last Month. Is it possible to have the

    each button
    >open up the correct month, ie Current Month would open

    ("January") and
    >Last Month open ("December")? If so, does anyone have any

    suggestions
    >as to how?
    >
    >TIA
    >
    >Steve
    >
    >.
    >


  4. #4
    Steve
    Guest

    Re: UserForm to select current month or earlier

    Jason

    Thanks a lot for replying. I'm playing about with the code, and I've
    got a userform button working to select the current month with :

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

    I'm relatively comfortable with constructing UserForms; it's the VB
    that goes with them that gets me

    Is there a quick'n'easy way of VBing 'Now' - 1 (month)? If not, your
    solution works excellently, thanks, but I'm still hoping I might get
    this done on a form.

    TIA

    Steve


  5. #5
    Registered User
    Join Date
    01-22-2004
    Location
    UK
    Posts
    27
    See my reply look at command button 2 it does what you want!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1