+ Reply to Thread
Results 1 to 10 of 10

Calendar Macro

Hybrid View

andrew8008 Calendar Macro 09-19-2007, 11:02 AM
Greg M Hi Andrew, You can use the... 09-19-2007, 12:29 PM
andrew8008 I am confused... What is the... 09-19-2007, 12:49 PM
Greg M Hi again, Excel triggers... 09-19-2007, 12:58 PM
royUK Have you tried the code? 09-19-2007, 12:58 PM
andrew8008 I tried the code and it... 09-19-2007, 01:10 PM
  1. #1
    Registered User
    Join Date
    05-23-2007
    Posts
    41

    Calendar Macro

    I have the following Calendar Macro. I want this to pop up when cell A5 is active vs assigning a Macro Button. How do I do? Thanks

     Sub OpenCalendar()
        frmCalendar.Show
    End Sub
    Last edited by VBA Noob; 09-19-2007 at 11:12 AM.

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641
    Hi Andrew,

    You can use the following code in the VBA module of the worksheet which contains the cell from which you want to trigger the routine:

    
    Option Explicit
    
    
    Const strCalendarCell   As String = "A5"
    
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
        If Target.Cells.Count = 1 And Not Intersect(Target, Me.Range(strCalendarCell)) Is Nothing Then
            frmCalendar.Show
        End If
    
    End Sub
    The check of "Target.Cells.Count = 1" just ensures that the routine won't be triggered if the user selects a multi-cell range which includes cell A5.

    Hope this helps - please let me know how you get on.

    Best regards,

    Greg M

  3. #3
    Registered User
    Join Date
    05-23-2007
    Posts
    41
    I am confused... What is the full code to show calendar pop up when cell "A5" is selected?

    Thanks

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641
    Hi again,

    Excel triggers the "Worksheet_SelectionChange" event whenever a cell or range of cells is selected.

    The "If" statement first checks that only a single cell is selected, and then checks that there is a valid intersection between the selected cell ("Target") and cell A5 ("strCalendarCell") - in this case, a "valid intersection" means that the selected cell and cell A5 are one and the same.

    When the "If" statement returns a value of TRUE, the "frmCalendar.Show" statement is executed.

    Regards,

    Greg M

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Quote Originally Posted by andrew8008
    I am confused... What is the full code to show calendar pop up when cell "A5" is selected?

    Thanks
    Have you tried the code?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  6. #6
    Registered User
    Join Date
    05-23-2007
    Posts
    41
    I tried the code and it doesn't seem to work. Please check attached file.

    I would also like to activate when "B5" is active along with "A5".

    Thanks for all your help!!!
    Attached Files Attached Files

  7. #7
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641
    Hi again,

    You entered the code in a standard VBA module - you must enter it in the VBA module for the WORKSHEET. Right-click on the worksheet tab & select "View Code" - this will display the VBA module for the worksheet.

    To extend the "activation range" use:

    Const strCalendarCell   As String = "A5:B5"
    Regards,

    Greg M

+ 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