PDA

View Full Version : Month wise calender macro



excel_1317
11-11-2013, 02:18 PM
I am trying to prepare month wise calender. So my spreadsheet has 12 tabs for each month. On top of each tab i want to place a macro which should hide all active tabs except for the month we want to view.

For eg. we are viewing Sept. 2013. At this point of time only sept. 2013 tab is visible.

On top left Aug, 2013 and top right Oct. 2013 is written. So when a user click on Aug 2013, All tabs should go invisible ONLY August 2013 remain visible. Same way when user click on Oct. 2013, All tabs should go invisible ONLY October 2013 remain visible.

Please see the attached excel. Thanks in advance1333

Mike H
11-11-2013, 04:32 PM
Hi,

ALT+F11 to open VB editor. Double click 'ThisWorkbook' and paste the code below in on the right. Close VB editor.
Click a worksheet month in Q4 to Q15.
Note you must now save your workbook as a macro enabled workbook with a .XLSM extension.




Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Dim x As Long
If Not Intersect(Target, Sh.Range("Q4:Q15")) Is Nothing Then
Application.EnableEvents = False
Application.ScreenUpdating = False
For x = 1 To Worksheets.Count
Sheets(x).Visible = True
Next
For x = 1 To Worksheets.Count
If UCase(Left(Sheets(x).Name, 3)) <> UCase(Left(Target.Value, 3)) Then
Sheets(x).Visible = False
End If
Next
Range(Target.Address).Select
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub

excel_1317
11-12-2013, 08:36 AM
Thank you Mike..!