Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Show Tabs by date

Is there a way to create a macro that will show the tabs at the bottom by the
current month? I have the tabs named by month, and only want it to show
January-Current month tabs only as it progresses through the year. So, for
instance, Tabs January, February, March, etc.... through September would be
showing right now, then next month, would include October.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Show Tabs by date

There are a couple different ways you could do this. I chose to use
an array of month names that correlate with the sheet names. This
will allow any sheets that are stuck inbetween months to not be
hidden. Edit this as you see fit.
Sub sheetHider()
Dim mthList As Variant, sht As Worksheet
mthList = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", _
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
If Month(Date) = 12 Then
MsgBox "No months to hide"
Else
For mth = Month(Date) + 1 To 12
For Each sht In ActiveWorkbook.Worksheets
If sht.Name = mthList(mth - 1) Then
sht.Visible = xlSheetHidden
End If
Next sht
Next mth
End If
End Sub
Tasha wrote:
Is there a way to create a macro that will show the tabs at the bottom by the
current month? I have the tabs named by month, and only want it to show
January-Current month tabs only as it progresses through the year. So, for
instance, Tabs January, February, March, etc.... through September would be
showing right now, then next month, would include October.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Show Tabs by date

One way:

Public Sub UpToCurrentMonth()
Dim i As Long
Dim nCurrentMonth As Long
nCurrentMonth = Month(Date)
For i = 1 To 12
Worksheets(Format(DateSerial(2007, i, 1), "mmmm")).Visible = _
i <= nCurrentMonth
Next i
End Sub

Note that the year in DateSerial(year,month,day) could be any valid year.


In article ,
Tasha wrote:

Is there a way to create a macro that will show the tabs at the bottom by the
current month? I have the tabs named by month, and only want it to show
January-Current month tabs only as it progresses through the year. So, for
instance, Tabs January, February, March, etc.... through September would be
showing right now, then next month, would include October.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Show Tabs by date

thanks so much, both of these worked!!! The last one serves my purpose
better because I can't have a prompt as the macro is run at night.



"JE McGimpsey" wrote:

One way:

Public Sub UpToCurrentMonth()
Dim i As Long
Dim nCurrentMonth As Long
nCurrentMonth = Month(Date)
For i = 1 To 12
Worksheets(Format(DateSerial(2007, i, 1), "mmmm")).Visible = _
i <= nCurrentMonth
Next i
End Sub

Note that the year in DateSerial(year,month,day) could be any valid year.


In article ,
Tasha wrote:

Is there a way to create a macro that will show the tabs at the bottom by the
current month? I have the tabs named by month, and only want it to show
January-Current month tabs only as it progresses through the year. So, for
instance, Tabs January, February, March, etc.... through September would be
showing right now, then next month, would include October.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Show Tabs by date

one more question, is there a way to select the current month worksheet?

"JE McGimpsey" wrote:

One way:

Public Sub UpToCurrentMonth()
Dim i As Long
Dim nCurrentMonth As Long
nCurrentMonth = Month(Date)
For i = 1 To 12
Worksheets(Format(DateSerial(2007, i, 1), "mmmm")).Visible = _
i <= nCurrentMonth
Next i
End Sub

Note that the year in DateSerial(year,month,day) could be any valid year.


In article ,
Tasha wrote:

Is there a way to create a macro that will show the tabs at the bottom by the
current month? I have the tabs named by month, and only want it to show
January-Current month tabs only as it progresses through the year. So, for
instance, Tabs January, February, March, etc.... through September would be
showing right now, then next month, would include October.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Show Tabs by date

One way:

Public Sub UpToCurrentMonth()
Dim i As Long
Dim nCurrentMonth As Long
nCurrentMonth = Month(Date)
For i = 1 To 12
Worksheets(Format(DateSerial(2007, i, 1), "mmmm")).Visible = _
i <= nCurrentMonth
Next i
Worksheets(Format(DateSerial(2007, nCurrentMonth, 1), "mmmm")).Select
End Sub



In article ,
Tasha wrote:

one more question, is there a way to select the current month worksheet?

"JE McGimpsey" wrote:

One way:

Public Sub UpToCurrentMonth()
Dim i As Long
Dim nCurrentMonth As Long
nCurrentMonth = Month(Date)
For i = 1 To 12
Worksheets(Format(DateSerial(2007, i, 1), "mmmm")).Visible = _
i <= nCurrentMonth
Next i
End Sub

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Show Tabs by date

The prompt is not really necessary. I just put it in for
demonstration purposes.
Sub sheetHider()
Dim mthList As Variant, sht As Worksheet
mthList = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", _
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
If Month(Date) < 12 Then
For mth = Month(Date) + 1 To 12
For Each sht In ActiveWorkbook.Worksheets
If sht.Name = mthList(mth - 1) Then
sht.Visible = xlSheetHidden
End If
Next sht
Next mth
End If
End Sub

JE McGimpsey wrote:
One way:

Public Sub UpToCurrentMonth()
Dim i As Long
Dim nCurrentMonth As Long
nCurrentMonth = Month(Date)
For i = 1 To 12
Worksheets(Format(DateSerial(2007, i, 1), "mmmm")).Visible = _
i <= nCurrentMonth
Next i
Worksheets(Format(DateSerial(2007, nCurrentMonth, 1), "mmmm")).Select
End Sub



In article ,
Tasha wrote:

one more question, is there a way to select the current month worksheet?

"JE McGimpsey" wrote:

One way:

Public Sub UpToCurrentMonth()
Dim i As Long
Dim nCurrentMonth As Long
nCurrentMonth = Month(Date)
For i = 1 To 12
Worksheets(Format(DateSerial(2007, i, 1), "mmmm")).Visible = _
i <= nCurrentMonth
Next i
End Sub


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Show Tabs by date

Tiny niggle: If the user has manually hidden one or more sheets,
including sheet "Jan", it is possible to get a run-time error with this
technique since at least one sheet must remain visible.



In article . com,
JW wrote:

The prompt is not really necessary. I just put it in for
demonstration purposes.
Sub sheetHider()
Dim mthList As Variant, sht As Worksheet
mthList = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", _
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
If Month(Date) < 12 Then
For mth = Month(Date) + 1 To 12
For Each sht In ActiveWorkbook.Worksheets
If sht.Name = mthList(mth - 1) Then
sht.Visible = xlSheetHidden
End If
Next sht
Next mth
End If
End Sub

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Show Tabs by date

JE, you are correct. That most certainly could happen. But that
could happen with your technique as well, correct?
JE McGimpsey wrote:
Tiny niggle: If the user has manually hidden one or more sheets,
including sheet "Jan", it is possible to get a run-time error with this
technique since at least one sheet must remain visible.



In article . com,
JW wrote:

The prompt is not really necessary. I just put it in for
demonstration purposes.
Sub sheetHider()
Dim mthList As Variant, sht As Worksheet
mthList = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", _
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
If Month(Date) < 12 Then
For mth = Month(Date) + 1 To 12
For Each sht In ActiveWorkbook.Worksheets
If sht.Name = mthList(mth - 1) Then
sht.Visible = xlSheetHidden
End If
Next sht
Next mth
End If
End Sub


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Show Tabs by date

Not correct.

With my technique, the January sheet will always be made visible as the
first step, even if the user has hidden it.



In article . com,
JW wrote:

JE, you are correct. That most certainly could happen. But that
could happen with your technique as well, correct?



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Show Tabs by date

Another idea is the use of "MonthName"

For m = 1 To 12
Worksheets(MonthName(m, False)).Visible = (i <= nCurrentMonth)

--
Dana DeLouis
Windows XP & Excel 2007


"JE McGimpsey" wrote in message
...
One way:

Public Sub UpToCurrentMonth()
Dim i As Long
Dim nCurrentMonth As Long
nCurrentMonth = Month(Date)
For i = 1 To 12
Worksheets(Format(DateSerial(2007, i, 1), "mmmm")).Visible = _
i <= nCurrentMonth
Next i
Worksheets(Format(DateSerial(2007, nCurrentMonth, 1), "mmmm")).Select
End Sub



In article ,
Tasha wrote:

one more question, is there a way to select the current month worksheet?

"JE McGimpsey" wrote:

One way:

Public Sub UpToCurrentMonth()
Dim i As Long
Dim nCurrentMonth As Long
nCurrentMonth = Month(Date)
For i = 1 To 12
Worksheets(Format(DateSerial(2007, i, 1), "mmmm")).Visible =
_
i <= nCurrentMonth
Next i
End Sub



  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Show Tabs by date

Yeah - MonthName() is a VBA6+ function, so I tend to forget about it
since I develop cross-platform applications, and I still have a
substantial minority of customers using WinXL97.

In article ,
"Dana DeLouis" wrote:

Another idea is the use of "MonthName"

For m = 1 To 12
Worksheets(MonthName(m, False)).Visible = (i <= nCurrentMonth)

  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Show Tabs by date

Ahhhh, said the blind man. Looked right over that. Smooth code.
JE McGimpsey wrote:
Not correct.

With my technique, the January sheet will always be made visible as the
first step, even if the user has hidden it.



In article . com,
JW wrote:

JE, you are correct. That most certainly could happen. But that
could happen with your technique as well, correct?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I get tabs to show in 2 or more rows? Drew[_2_] Excel Discussion (Misc queries) 4 April 2nd 08 11:14 PM
Show Data from Various Tabs in one Tab within the same worksheet Ardy Excel Programming 2 December 13th 06 08:36 PM
What's wrong with my procedure to show tabs? JK Excel Programming 1 September 16th 05 05:47 AM
Help file show tabs Ron Excel Discussion (Misc queries) 0 August 30th 05 02:50 PM
Compare two tabs and only show exceptions Rich Excel Discussion (Misc queries) 3 June 15th 05 02:32 PM


All times are GMT +1. The time now is 10:02 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"