Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Still trying to find the date

I think I have the code to loop through worksheets to find the date on
the correct sheet. Now I am getting an error called type mismatch.

here is my code for some reason it isn't pulling the data from the cell
into lookup

Private Sub workbook_open()
Dim ws As Worksheet
Dim today As Long
Dim lookup As Long
today = Date
For Each ws In ActiveWorkbook.Worksheets
lookup = ws.Cells("b3:b3").Value
If lookup = today Then
ws.Activate

End If
Next


End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Still trying to find the date

How about:

Option Explicit
Private Sub workbook_open()
Dim ws As Worksheet
Dim today As Long
Dim lookup As Long
Dim FoundIt As Boolean
FoundIt = False
today = Date
For Each ws In ActiveWorkbook.Worksheets
'notice the .value2 here
If IsNumeric(ws.Range("B3").Value2) Then
lookup = CLng(ws.Range("b3").Value2)
If lookup = today Then
ws.Activate
FoundIt = True
Exit For
End If
End If
Next ws

If FoundIt = False Then
MsgBox "It wasn't found!"
End If
End Sub

And .cells("B3:B3") would have to be .cells(3,"B") or .cells(3,3). But
..Range("B3") is prettier in this case.

bpotter wrote:

I think I have the code to loop through worksheets to find the date on
the correct sheet. Now I am getting an error called type mismatch.

here is my code for some reason it isn't pulling the data from the cell
into lookup

Private Sub workbook_open()
Dim ws As Worksheet
Dim today As Long
Dim lookup As Long
today = Date
For Each ws In ActiveWorkbook.Worksheets
lookup = ws.Cells("b3:b3").Value
If lookup = today Then
ws.Activate

End If
Next

End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Still trying to find the date


Thanks That helped alot!!!

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
Find Specific date in Biwwekly Based on date jlclyde Excel Discussion (Misc queries) 3 January 27th 09 09:15 PM
Julian date - find next highest date/number jchick0909 Excel Worksheet Functions 1 March 20th 08 11:38 PM
Find the date of the coming up Saturday given the current date. Michael Ermino Excel Worksheet Functions 4 April 11th 07 02:48 AM
Using variables to make a date and using find method to find that. KyWilde Excel Programming 2 April 21st 05 09:43 PM
Find date and copy range based on that date avzundert Excel Programming 2 November 25th 04 10:31 AM


All times are GMT +1. The time now is 03:47 AM.

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"