Open on this week's sheet

lapta301

Well-known Member
Joined
Nov 12, 2004
Messages
1,001
Office Version
  1. 365
Platform
  1. Windows
Dear All

I have a sheet for each week of the year dated for the Monday week commencing in the format yyyy-mm-dd so that this week's sheet is 2011-09-19.

What I would like is for the cursor to be placed in cell B5 for this weeks sheet when the workbook is opened.

If the correct weekly sheet doesn't exist then a warning message should be shown.

I hope that someone will be able to assist.

Many thanks
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
GTO

Not sure if you will pick this up but I have a request for an addition to this code.

This code works absolutely perfectly but I have a special sheet named control that I would like moved to the left of whatever the current weeks sheet is.

So when I open the workbook today the code will find the weekly sheet dated 2012-06-18 and what I would like is for the control sheet to be moved from wherever it is to the left of the sheet named 2012-06-18

I hope that this makes sense and regardless of whether or not this can be done the original code is beautiful and makes daily life much easier when opening up the many workbooks that I have with weekly sheets.

Regards from a sunny Southern England
 
Last edited:
Upvote 0
Try

Rich (BB code):
Private Sub Workbook_Open()
Dim wksInitial      As Worksheet
Dim rngCheckBlank   As Range
Dim lRowInRange     As Long
    
    On Error Resume Next
    Set wksInitial = ThisWorkbook.Worksheets(Format(Date - Weekday(Date, vbMonday) + 1, "yyyy-mm-dd"))
    On Error GoTo 0
    
    'Instead of placing cursor in cell B5 it needs to go in the first empty cell in the range A24:A87
    If Not wksInitial Is Nothing Then
        Set rngCheckBlank = wksInitial.Range("A24:A87")
        
        '// Evaluate is expensive, not a loop though, so maybe...   //
        On Error Resume Next
        lRowInRange = Evaluate("MATCH(TRUE,'" & rngCheckBlank.Parent.Name & "'!" & rngCheckBlank.Address & "="""",0)")
        On Error GoTo 0
        
        If lRowInRange Then
            Application.Goto wksInitial.Cells(23 + lRowInRange, 1)
        Else
            Application.Goto wksInitial.Cells(5, 2)
        End If
        Worksheets("control").Move before:=ActiveSheet
    Else
        MsgBox Format(Date - Weekday(Date, vbMonday) + 1, "yyyy-mm-dd") & " doesn't exist"
    End If
End Sub
 
Upvote 0
Hi Peter

We meet again

Sort of works other than the Control sheet has now become the active sheet rather than the weekly sheet.
 
Upvote 0
Then maybe

Code:
Private Sub Workbook_Open()
Dim wksInitial      As Worksheet
Dim rngCheckBlank   As Range
Dim lRowInRange     As Long
    
    On Error Resume Next
    Set wksInitial = ThisWorkbook.Worksheets(Format(Date - Weekday(Date, vbMonday) + 1, "yyyy-mm-dd"))
    On Error GoTo 0
    
    'Instead of placing cursor in cell B5 it needs to go in the first empty cell in the range A24:A87
    If Not wksInitial Is Nothing Then
        Set rngCheckBlank = wksInitial.Range("A24:A87")
        
        '// Evaluate is expensive, not a loop though, so maybe...   //
        On Error Resume Next
        lRowInRange = Evaluate("MATCH(TRUE,'" & rngCheckBlank.Parent.Name & "'!" & rngCheckBlank.Address & "="""",0)")
        On Error GoTo 0
        Worksheets("control").Move before:=wksInitial
        
        If lRowInRange Then
            Application.Goto wksInitial.Cells(23 + lRowInRange, 1)
        Else
            Application.Goto wksInitial.Cells(5, 2)
        End If
    Else
        MsgBox Format(Date - Weekday(Date, vbMonday) + 1, "yyyy-mm-dd") & " doesn't exist"
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,682
Members
452,937
Latest member
Bhg1984

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top