View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
[email protected] james.billy@gmail.com is offline
external usenet poster
 
Posts: 69
Default Sheet name ref in cell B2 and then!

1) As far as I know there isn't a way to get the sheet name without
using VBA, using VBA though you could put some code in the workbook
sheet activate event, something like:

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Range("B2").Value = ActiveSheet.Name
End Sub

What this will do is everytime a sheet is selected the sheet name will
be put into Range B2.

2) You would have to put some code in the workbook open event something
like:

Private Sub Workbook_Open()
Dim xSheet As Worksheet
Dim tmpDate As String
tmpDate = Format(Date, "mmm-yy")
Application.enableevents = false
For Each xSheet In ThisWorkbook.Sheets
If xSheet.Name < tmpDate Then
xSheet.Visible = xlHidden
End If
Next xSheet
Application.EnableEvents = true
Range("B2").value = Activesheet.name
End Sub

This would get the system date and format it to the first three letters
of the month followed by the year so at the minute it would return
Aug-06, the rest of the code will cycle through all of your sheets
hiding any sheets that do not match this name. The precursor to this
approach would be that you would have to be very consistent when naming
your worksheets, secondly you would have to make sure that the sheet
exists before the month ie the worksheet Sep-06 is created before
September. Either that or you would need some error handling which in
this instance I would suggest anyway.

I wasn't sure if you wanted your review sheet visible or not, if you
want it visible just change this "If xSheet.Name < tmpDate Then" line
to:

If xSheet.Name < tmpDate and xSheet < "Review Sheet" Then

James

Jay wrote:

Guys, what I'd like to do is a two part process:

1.) Show the current sheet name in cell B2 of that sheet. I have the sheets
named as: Jan 2006, Feb 2006, March 2006, April 2006, etc, etc, etc

Then

2.) When the work book is opened, to open it to the current/active month
(Jan 2006, Feb 2006, March 2006, April 2006, etc, etc, etc), and keep the
other similarly named month sheets, minus the review sheet hidden. This, I
know will require some coding, maybe not, I'm not sure. Given the nature of
this application, however, would the second (question #2) part be possible
also?

Looking forward to your reply....

Thanks