+ Reply to Thread
Results 1 to 9 of 9

Calendar with restricted dates to select

Hybrid View

  1. #1
    Registered User
    Join Date
    09-26-2008
    Location
    North Myrtle Beach
    MS-Off Ver
    365 Business
    Posts
    82

    Question Calendar with restricted dates to select

    Is there a way to have a calendar pop up when a particular cell is selected and only have Sunday dates as optional selections? Needs to be able to scroll by month.

    Thanks! You all have been sooo helpful!
    Last edited by bjohnsonac; 03-20-2009 at 11:10 AM.

  2. #2
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Calendar with restricted dates to select

    Hi, On your Toolbar Select, "View","Toolbars", "Control ToolBox", at the bottom of the menu , there is an icon (Looks like Hammer & Spanner) Icon Says "More Controls", Click this and Select Calendar from the list, Click sheet, Calendar Appears on sheet.

    Right click youy sheet, Select "View Code", VB Window appears.
    Paste Both the codes (in one) into the Window.
    Close Window
    When you click in sheet the Calendar should disappear and when you click cell "A1" it reappears.
    The calendar Code tells you, when you click a Weekday or the Weekend.
    You need to alter it to do what you want.
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address = "$A$1" Then
        Calendar1.Visible = True
    Else
        Calendar1.Visible = False
    End If
    End Sub
    Private Sub Calendar1_Click()
    If Not Weekday(Calendar1.Value) = 1 Xor Not _
        Weekday(Calendar1.Value) = 7 Then
        MsgBox "Do something"
    Else
        MsgBox "You Selected a Week Day"
    Exit Sub
    End If
    End Sub
    Regards Mick
    Last edited by MickG; 03-18-2009 at 01:22 PM.

  3. #3
    Registered User
    Join Date
    09-26-2008
    Location
    North Myrtle Beach
    MS-Off Ver
    365 Business
    Posts
    82

    Re: Calendar with restricted dates to select

    Thanks Mick! A couple questions...
    1. Once they select a date, how do I ensure that cell gets populated with the date they select?
    2. Is there a way to create a "STOP" if they try to click past the date selection?
    3. The calendar shows up when I open the workbook, but not necessarily when I click on the specific cell "I4" - I need it to show up EVERYTIME they click on cell "I4" and force them to make a selection that is a Sunday date.

  4. #4
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Calendar with restricted dates to select

    Hi, Sorry I misread your Thread.
    This code will allow a Sunday Date to be selected which will be transferred, on selection to the Active cell.
    If any oher Days are selected you will get an error message.
    The Calendar will show when you click "I4", and disappear when you click "I1".
    Change these addresses to suit you.
    If the Calendar does not appear, Click "Alt + F11" to view the VB Editor window. On the Toolbar Click The "Green Triangle" to Ensure the Blue Suare to its left is Dark Blue. This is to ensure you are in "run mode".
    Exit the editer & try again.
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address = "$I$4" Then
        Calendar1.Visible = True
    ElseIf Target.Address = "$I$1" Then
        Calendar1.Visible = False
    End If
    End Sub
    Private Sub Calendar1_Click()
    Dim Msg As String
    If Not Weekday(Calendar1.Value) = 1 Then
            Msg = MsgBox("You Selected a Week Day" & Chr(10) & "Please Try Again !!", vbExclamation)
    Exit Sub
        Else
    Selection = Calendar1.Value
    End If
    End Sub
    Regards
    Mick

  5. #5
    Registered User
    Join Date
    09-26-2008
    Location
    North Myrtle Beach
    MS-Off Ver
    365 Business
    Posts
    82

    Re: Calendar with restricted dates to select

    Mick, I got most of it working now thanks to you! The only thing I can't get to work is having the calendar disappear once the user clicks off cell $I$4....ideally, once they enter a date, I would like for the cursor to automaticlly move to cell $A$5 and have the calendar disappear, but if they return to cell $I$4 at any time the calendar should re-appear....

    Here is my current code:
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address = "$I$4" Then
        Calendar1.Visible = True
    ElseIf Target.Address = "$A$5" Then
        Calendar1.Visible = False
    End If
    End Sub
    Private Sub Calendar1_Click()
    Dim Msg As String
    If Not Weekday(Calendar1.Value) = 1 Then
            Msg = MsgBox("You Selected a Week Day" & Chr(10) & "Please Try Again !!", vbExclamation)
    Exit Sub
        Else
        Range("$I$4").Select
    Selection = Calendar1.Value
        
    End If
    End Sub
    Thanks again for all your help! This thing is almost done now and I can then move onto my next project

  6. #6
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Calendar with restricted dates to select

    Hi, Try this:-
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address = "$I$4" Then
        Calendar1.Visible = True
    End If
    End Sub
    Private Sub Calendar1_Click()
    Dim Msg As String
    If Not Weekday(Calendar1.Value) = 1 Then
            Msg = MsgBox("You Selected a Week Day" & Chr(10) & "Please Try Again !!", vbExclamation)
            Exit Sub
       Else
            Range("$I$4") = Calendar1.Value
            Calendar1.Visible = False
            Range("a5").Select
    End If
    End Sub
    Regards Mick

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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