CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 1999
    Location
    New Orleans
    Posts
    1

    Excel and worksheet iteration

    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










  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: Excel and worksheet iteration

    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured