Excel date lookup using several worksheets

  • Thread starter Thread starter bpotter
  • Start date Start date
B

bpotter

I am writing a macro in workbook_open
what I am wanting to do is search through my workbook for todays date
in a certain range.
then activate that workbook.

I currently have this code

Private Sub Workbook_Open()

Dim dates As Range
Dim cell As Range
Dim ws As Worksheet
Worksheets(Day(1)).Activate

For Each ws In Worksheets
On Error Resume Next
Worksheets(ws.Name).Activate
Set dates = Range("b3")
Set cell = dates.Find(Date)
If Not cell Is Nothing Then
cell.Activate
Exit For
End If

Next ws

End Sub

But it keeps giveing me the wrong sheet. It selects the last sheet in
the workbook.
Any help would greatly be appreciated.
 
You're only looking at one cell.

Set dates = Range("b3")
maybe:
Set dates = Range("b:B")

So your loop is not finding anything and it just finishes at with the last
sheet.
 
I am looking in cell b3 on each sheet looking for the date.
For some reason it will not find the date specified. I also went into
the cell and made sure that it was reading the date right and it was.
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top