Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Rob Rob is offline
external usenet poster
 
Posts: 718
Default Finding Worksheet and Activating it

How would I go about searching for a specific worksheet and activating it
upon opening a workbook?

The worksheet should be named as Todays month and date, like this... 1-30.

This is what I have started...

Private Sub Workbook_Open()
Dim yDay, tDay, yMth, tMth
Dim dFri, dMon, dNow

yDay = Day(Date) - 1
tDay = Day(Date)
yMth = Month(Date) - 1
tMth = Month(Date)
dFri = 6
dMon = 2
dNow = Weekday(Date)


If Sheets(tMth & "-" & tDay).Name = True Then

Sheets(tMth & "-" & tDay).Activate
Exit Sub

Else
MsgBox "Please create a sheet for today", vbOKOnly

End If

End Sub

Any help would be awesome.

Thanks in advance,
Rob
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Finding Worksheet and Activating it

One way:

Option Explicit
Private Sub Workbook_Open()

Dim myStr As String
Dim wks As Worksheet

myStr = Format(Date, "m-d")

Set wks = Nothing
On Error Resume Next
Set wks = Me.Worksheets(myStr)
On Error GoTo 0

If wks Is Nothing Then
MsgBox "Please create a sheet for today", vbOKOnly
Else
Application.Goto wks.Range("A1"), Scroll:=True
End If

End Sub

Just a suggestion...

You may want to create worksheets that are named in yyyy-mm-dd format. It could
make sorting easier and you won't have to worry about next year's worksheet
names.

Rob wrote:

How would I go about searching for a specific worksheet and activating it
upon opening a workbook?

The worksheet should be named as Todays month and date, like this... 1-30.

This is what I have started...

Private Sub Workbook_Open()
Dim yDay, tDay, yMth, tMth
Dim dFri, dMon, dNow

yDay = Day(Date) - 1
tDay = Day(Date)
yMth = Month(Date) - 1
tMth = Month(Date)
dFri = 6
dMon = 2
dNow = Weekday(Date)


If Sheets(tMth & "-" & tDay).Name = True Then

Sheets(tMth & "-" & tDay).Activate
Exit Sub

Else
MsgBox "Please create a sheet for today", vbOKOnly

End If

End Sub

Any help would be awesome.

Thanks in advance,
Rob


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
Rob Rob is offline
external usenet poster
 
Posts: 718
Default Finding Worksheet and Activating it

That Works Beautifully!!!

Thank You Sooo Very Much!
Rob


"Dave Peterson" wrote:

One way:

Option Explicit
Private Sub Workbook_Open()

Dim myStr As String
Dim wks As Worksheet

myStr = Format(Date, "m-d")

Set wks = Nothing
On Error Resume Next
Set wks = Me.Worksheets(myStr)
On Error GoTo 0

If wks Is Nothing Then
MsgBox "Please create a sheet for today", vbOKOnly
Else
Application.Goto wks.Range("A1"), Scroll:=True
End If

End Sub

Just a suggestion...

You may want to create worksheets that are named in yyyy-mm-dd format. It could
make sorting easier and you won't have to worry about next year's worksheet
names.

Rob wrote:

How would I go about searching for a specific worksheet and activating it
upon opening a workbook?

The worksheet should be named as Todays month and date, like this... 1-30.

This is what I have started...

Private Sub Workbook_Open()
Dim yDay, tDay, yMth, tMth
Dim dFri, dMon, dNow

yDay = Day(Date) - 1
tDay = Day(Date)
yMth = Month(Date) - 1
tMth = Month(Date)
dFri = 6
dMon = 2
dNow = Weekday(Date)


If Sheets(tMth & "-" & tDay).Name = True Then

Sheets(tMth & "-" & tDay).Activate
Exit Sub

Else
MsgBox "Please create a sheet for today", vbOKOnly

End If

End Sub

Any help would be awesome.

Thanks in advance,
Rob


--

Dave Peterson

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 to auto populate an invoice from data in an existing worksheet juliebythesea Excel Discussion (Misc queries) 5 October 28th 09 08:14 AM
Activating a Worksheet? Kenny R Excel Discussion (Misc queries) 3 December 8th 06 05:15 PM
Activating a worksheet through use of a variable Cads Excel Worksheet Functions 2 February 7th 06 10:45 AM
Macro or OLE method to insert worksheet from template workbook Lyndon Rickards Excel Discussion (Misc queries) 0 January 30th 06 08:46 PM
Activating "Todays Date" column upon opening? Jeremy H via OfficeKB.com Excel Discussion (Misc queries) 3 August 25th 05 02:36 AM


All times are GMT +1. The time now is 11:08 PM.

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

About Us

"It's about Microsoft Excel"