Workbook to open to a specific sheet and select cell with today's date

Greep3r

New Member
Joined
Aug 28, 2019
Messages
3
Hi

I have a question about the below code:

Code:
Private Sub Workbook_Open()    Dim CellToShow As Range
    Worksheets("Smart City Projects Schedule").Select
    x = DateTime.Date
    Set CellToShow = Worksheets("Smart City Projects Schedule").Rows(6).Find(What:=x, LookIn:=xlValues)
    If CellToShow Is Nothing Then
        MsgBox "No Cell for day " & x & " found.", vbCritical
    Else
        With CellToShow
            .Select
            .Show 'Scroll the window to show the cell
        End With
    End If
End Sub

Upon opening the workbook the correct sheet within the workbook but the only condition where the correct cell with today's date is chosen is if I have the cell format set to "yyyy/mm/dd".
1vnFysNIbKSK9mLQIpdohYR-uvDioHv_0

open

open


This would not be a problem but seeing that this is a ghantt chart with a huge amount of rows I need to keep the column width as small as possible. When I change the cell format to only show "dd" I get an error that the value cannot be found. If I make the column width smaller to show "##" I get the same error message of value not found. The only condition where the code works properly is if the date is fully visible and set to "yyyy/mm/dd".

Any suggestion how this can be addressed to work properly?

Regards
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi,
as an idea, try changing this line

Code:
 Set CellToShow = Worksheets("Smart City Projects Schedule").Rows(6).Find(What:=x, LookIn:=xlValues)


to this

Code:
 Set CellToShow = Worksheets("Smart City Projects Schedule").Rows(6).Find(What:=x, LookIn:=xlFormulas, lookat:=xlWhole)

and see if this will do what you want when cell formatted to display your dates as "dd"

Dave
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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