Click to See Complete Forum and Search --> : Excel and worksheet iteration


averyww
October 6th, 1999, 01:29 PM
I am programming Excel for a friend and need to iterate through all of the worksheets to check for a condition ( to determine if a date matches - the date is in a certain cell - the user enters the date required to match). I have tried every kind of flow statement, hoeveer, I feel the the For each sheet ..... Next sheet should do it and it doesn't. Here is the code

[
Dim visit_date As Date
Dim F As String
Dim sheet As Worksheet
' nurse enters visit date to search

visit_date = InputBox("Enter Clinic Date:")

' check against next visit date for match
' if match, then set F as variable for next F visit

For Each sheet In Workbooks("l_soca.xls").Worksheets
If Range("A5").Value = visit_date Then
F = Range("B5").Value

lots more cled

End If
Next sheet


End Sub]


What am I doing wrong?

thank you in advance, gerry

Lothar Haensler
October 7th, 1999, 06:24 AM
you didn't specify what exactly the problem is.
From the code I can only assume that the Range object is not pointing to the correct sheet.
Try something like this.
for each sheet in ...
with sheet
.range(...)
end with
next sheet
->this time you are referencing the current sheet.