Auto open vba select column

excellence

Board Regular
Joined
Oct 5, 2005
Messages
155
Office Version
  1. 365
Platform
  1. MacOS
I have this vba to auto open and find today's date from column A and select the cell next to it in column B


Private Sub Workbook_Open()
Dim myDate As Variant, rng As Range
Set rng = Range("A1:A68")
Set myDate = rng.Find(What:=Int(Date), LookIn:=xlFormulas)
Cells(myDate.Row, myDate.Column + 1).Select

End Sub
I have dates in column spanning todays date
I've got it in sheet 1 but doesn't seem to work

Thanks for any help
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi there,

It doesn't to be any issue in your code.

However, if you have multipler sheets in that template, you might need to specify your sheet name / sheet number like below:

VBA Code:
Private Sub Workbook_Open()
Dim myDate As Variant, rng As Range
Set rng = Worksheets(1).Range("A1:A68")
Set myDate = rng.Find(What:=Int(Date), LookIn:=xlFormulas)
Worksheets(1).Activate
Worksheets(1).Cells(myDate.Row, myDate.Column + 1).Select

End Sub

Remember to put this code inside "Workbook", not in a particular module:
1714014205248.png
 
Upvote 0
Solution
Hi there,

It doesn't to be any issue in your code.

However, if you have multipler sheets in that template, you might need to specify your sheet name / sheet number like below:

VBA Code:
Private Sub Workbook_Open()
Dim myDate As Variant, rng As Range
Set rng = Worksheets(1).Range("A1:A68")
Set myDate = rng.Find(What:=Int(Date), LookIn:=xlFormulas)
Worksheets(1).Activate
Worksheets(1).Cells(myDate.Row, myDate.Column + 1).Select

End Sub

Remember to put this code inside "Workbook", not in a particular module:
View attachment 110480
Hi
I put it in this workbook and still no luck. Copied and pasted your vba
On left side looks like yours VBA >MS Excel Objects>Sheet1 and This Workbook under it
 
Upvote 0
Try:
VBA Code:
Private Sub Workbook_Open()
    Dim myDate As Range, rng As Range
    Set rng = Sheets("Sheet1").Range("A1:A68") 'change sheet name as needed
    Set myDate = rng.Find(What:=Int(Date), LookIn:=xlValues)
    If Not myDate Is Nothing Then
        myDate.Offset(0, 1).Select 
        MsgBox "Today's date not found in the specified range.", vbExclamation
    End If
End Sub
 
Upvote 0
the right side, however has the name of the macro as the title with General and Declarations underneath it
 
Upvote 0
Private Sub Workbook_Open() Dim myDate As Range, rng As Range Set rng = Sheets("Sheet1").Range("A1:A68") 'change sheet name as needed Set myDate = rng.Find(What:=Int(Date), LookIn:=xlValues) If Not myDate Is Nothing Then myDate.Offset(0, 1).Select MsgBox "Today's date not found in the specified range.", vbExclamation End If End Sub
Did not work. I must have something in the wrong place
 
Upvote 0
How are your dates formatted? Are they from a formula or value?
 
Upvote 0
Hi there,

It doesn't to be any issue in your code.

However, if you have multipler sheets in that template, you might need to specify your sheet name / sheet number like below:

VBA Code:
Private Sub Workbook_Open()
Dim myDate As Variant, rng As Range
Set rng = Worksheets(1).Range("A1:A68")
Set myDate = rng.Find(What:=Int(Date), LookIn:=xlFormulas)
Worksheets(1).Activate
Worksheets(1).Cells(myDate.Row, myDate.Column + 1).Select

End Sub

Remember to put this code inside "Workbook", not in a particular module:
View attachment 110480
Got it
So many thanks. I thought I got it in workbook but hadn't
 
Upvote 0
the right side, however has the name of the macro as the title with General and Declarations underneath it
Yes, initially when you select "Thisworkbook", you will see "General" and "Declaration".

1714017209114.png


Just make sure to select dropdown "Workbook"
1714017244657.png


and select "Open":
1714017280884.png


Then insert the codes.

Thanks to Cubist
which provided a better code. (you missed out "else" in the if condition)
Here is my code update:

VBA Code:
Private Sub Workbook_Open()
    Dim myDate As Range, rng As Range
    Set rng = Sheets("Sheet1").Range("A1:A68") 'change sheet name as needed
    Set myDate = rng.Find(What:=Int(Date), LookIn:=xlValues)
    If Not myDate Is Nothing Then
        Sheets("Sheet1").Activate
        myDate.Offset(0, 1).Select
        Else
        MsgBox "Today's date not found in the specified range.", vbExclamation
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,182
Members
452,615
Latest member
bogeys2birdies

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