+ Reply to Thread
Results 1 to 12 of 12

Loop Through All Open Workbooks

  1. #1
    scott
    Guest

    Loop Through All Open Workbooks

    I'm trying to find an example of looping through all open workbooks and
    doing a simple search of all cells to determine if a certain value exists in
    any of the workbooks.

    Any help?



  2. #2
    Tom Ogilvy
    Guest

    Re: Loop Through All Open Workbooks

    Dim bk as Workbook, sh as Worksheet
    Dim rng as Range, ans as long
    for each bk in application.Workbooks
    for each sh in bk.Worksheets
    set rng = sh.cells.Find("string")
    if not rng is nothing then
    msgbox "Found at " & rng.Address(external:=True)
    ans = msgbox "Continue to search",vbYesNo
    if ans = vbNo then exit sub
    end if
    Next
    Next

    --
    Regards,
    Tom Ogilvy

    "scott" <[email protected]> wrote in message
    news:[email protected]...
    > I'm trying to find an example of looping through all open workbooks and
    > doing a simple search of all cells to determine if a certain value exists

    in
    > any of the workbooks.
    >
    > Any help?
    >
    >




  3. #3
    Bob Phillips
    Guest

    Re: Loop Through All Open Workbooks


    For Each wb In Application.Workbooks
    If Application.CountIf(wb.Worksheets(1).Cells,"myValue) > 1 Then
    MsgBox "Found in " & wb.Name
    End If
    Next wb

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "scott" <[email protected]> wrote in message
    news:[email protected]...
    > I'm trying to find an example of looping through all open workbooks and
    > doing a simple search of all cells to determine if a certain value exists

    in
    > any of the workbooks.
    >
    > Any help?
    >
    >




  4. #4
    scott
    Guest

    Re: Loop Through All Open Workbooks

    Thank you again for saving sanity.

    "Tom Ogilvy" <[email protected]> wrote in message
    news:%[email protected]...
    > Dim bk as Workbook, sh as Worksheet
    > Dim rng as Range, ans as long
    > for each bk in application.Workbooks
    > for each sh in bk.Worksheets
    > set rng = sh.cells.Find("string")
    > if not rng is nothing then
    > msgbox "Found at " & rng.Address(external:=True)
    > ans = msgbox "Continue to search",vbYesNo
    > if ans = vbNo then exit sub
    > end if
    > Next
    > Next
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    > "scott" <[email protected]> wrote in message
    > news:[email protected]...
    >> I'm trying to find an example of looping through all open workbooks and
    >> doing a simple search of all cells to determine if a certain value exists

    > in
    >> any of the workbooks.
    >>
    >> Any help?
    >>
    >>

    >
    >




  5. #5
    scott
    Guest

    Re: Loop Through All Open Workbooks

    tom, can you look at the line

    ans = msgbox "Continue to search",vbYesNo

    it has a syntax error. thanks


    "Tom Ogilvy" <[email protected]> wrote in message
    news:%[email protected]...
    > Dim bk as Workbook, sh as Worksheet
    > Dim rng as Range, ans as long
    > for each bk in application.Workbooks
    > for each sh in bk.Worksheets
    > set rng = sh.cells.Find("string")
    > if not rng is nothing then
    > msgbox "Found at " & rng.Address(external:=True)
    > ans = msgbox "Continue to search",vbYesNo
    > if ans = vbNo then exit sub
    > end if
    > Next
    > Next
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    > "scott" <[email protected]> wrote in message
    > news:[email protected]...
    >> I'm trying to find an example of looping through all open workbooks and
    >> doing a simple search of all cells to determine if a certain value exists

    > in
    >> any of the workbooks.
    >>
    >> Any help?
    >>
    >>

    >
    >




  6. #6
    scott
    Guest

    Re: Loop Through All Open Workbooks

    can you correct syntax error in line

    If Application.CountIf(wb.Worksheets(1).Cells,"myValue) > 1 Then


    thanks

    "Bob Phillips" <[email protected]> wrote in message
    news:%[email protected]...
    >
    > For Each wb In Application.Workbooks
    > If Application.CountIf(wb.Worksheets(1).Cells,"myValue) > 1 Then
    > MsgBox "Found in " & wb.Name
    > End If
    > Next wb
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "scott" <[email protected]> wrote in message
    > news:[email protected]...
    >> I'm trying to find an example of looping through all open workbooks and
    >> doing a simple search of all cells to determine if a certain value exists

    > in
    >> any of the workbooks.
    >>
    >> Any help?
    >>
    >>

    >
    >




  7. #7
    Tom Ogilvy
    Guest

    Re: Loop Through All Open Workbooks

    ans = msgbox( "Continue to search",vbYesNo)

    --
    regards,
    Tom Ogilvy

    "scott" <[email protected]> wrote in message
    news:[email protected]...
    > tom, can you look at the line
    >
    > ans = msgbox "Continue to search",vbYesNo
    >
    > it has a syntax error. thanks
    >
    >
    > "Tom Ogilvy" <[email protected]> wrote in message
    > news:%[email protected]...
    > > Dim bk as Workbook, sh as Worksheet
    > > Dim rng as Range, ans as long
    > > for each bk in application.Workbooks
    > > for each sh in bk.Worksheets
    > > set rng = sh.cells.Find("string")
    > > if not rng is nothing then
    > > msgbox "Found at " & rng.Address(external:=True)
    > > ans = msgbox "Continue to search",vbYesNo
    > > if ans = vbNo then exit sub
    > > end if
    > > Next
    > > Next
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > > "scott" <[email protected]> wrote in message
    > > news:[email protected]...
    > >> I'm trying to find an example of looping through all open workbooks and
    > >> doing a simple search of all cells to determine if a certain value

    exists
    > > in
    > >> any of the workbooks.
    > >>
    > >> Any help?
    > >>
    > >>

    > >
    > >

    >
    >




  8. #8
    Tom Ogilvy
    Guest

    Re: Loop Through All Open Workbooks

    If Application.CountIf(wb.Worksheets(1).Cells,"myValue") > 1 Then

    --
    Regards,
    Tom Ogilvy


    "scott" <[email protected]> wrote in message
    news:[email protected]...
    > can you correct syntax error in line
    >
    > If Application.CountIf(wb.Worksheets(1).Cells,"myValue) > 1 Then
    >
    >
    > thanks
    >
    > "Bob Phillips" <[email protected]> wrote in message
    > news:%[email protected]...
    > >
    > > For Each wb In Application.Workbooks
    > > If Application.CountIf(wb.Worksheets(1).Cells,"myValue) > 1 Then
    > > MsgBox "Found in " & wb.Name
    > > End If
    > > Next wb
    > >
    > > --
    > >
    > > HTH
    > >
    > > RP
    > > (remove nothere from the email address if mailing direct)
    > >
    > >
    > > "scott" <[email protected]> wrote in message
    > > news:[email protected]...
    > >> I'm trying to find an example of looping through all open workbooks and
    > >> doing a simple search of all cells to determine if a certain value

    exists
    > > in
    > >> any of the workbooks.
    > >>
    > >> Any help?
    > >>
    > >>

    > >
    > >

    >
    >




  9. #9
    Bob Phillips
    Guest

    Re: Loop Through All Open Workbooks

    ans = msgbox( "Continue to search",vbYesNo)


    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "scott" <[email protected]> wrote in message
    news:[email protected]...
    > tom, can you look at the line
    >
    > ans = msgbox "Continue to search",vbYesNo
    >
    > it has a syntax error. thanks
    >
    >
    > "Tom Ogilvy" <[email protected]> wrote in message
    > news:%[email protected]...
    > > Dim bk as Workbook, sh as Worksheet
    > > Dim rng as Range, ans as long
    > > for each bk in application.Workbooks
    > > for each sh in bk.Worksheets
    > > set rng = sh.cells.Find("string")
    > > if not rng is nothing then
    > > msgbox "Found at " & rng.Address(external:=True)
    > > ans = msgbox "Continue to search",vbYesNo
    > > if ans = vbNo then exit sub
    > > end if
    > > Next
    > > Next
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > > "scott" <[email protected]> wrote in message
    > > news:[email protected]...
    > >> I'm trying to find an example of looping through all open workbooks and
    > >> doing a simple search of all cells to determine if a certain value

    exists
    > > in
    > >> any of the workbooks.
    > >>
    > >> Any help?
    > >>
    > >>

    > >
    > >

    >
    >




  10. #10
    Bob Phillips
    Guest

    Re: Loop Through All Open Workbooks

    If Application.CountIf(wb.Worksheets(1).Cells,"myValue") > 1 Then


    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "scott" <[email protected]> wrote in message
    news:[email protected]...
    > can you correct syntax error in line
    >
    > If Application.CountIf(wb.Worksheets(1).Cells,"myValue) > 1 Then
    >
    >
    > thanks
    >
    > "Bob Phillips" <[email protected]> wrote in message
    > news:%[email protected]...
    > >
    > > For Each wb In Application.Workbooks
    > > If Application.CountIf(wb.Worksheets(1).Cells,"myValue) > 1 Then
    > > MsgBox "Found in " & wb.Name
    > > End If
    > > Next wb
    > >
    > > --
    > >
    > > HTH
    > >
    > > RP
    > > (remove nothere from the email address if mailing direct)
    > >
    > >
    > > "scott" <[email protected]> wrote in message
    > > news:[email protected]...
    > >> I'm trying to find an example of looping through all open workbooks and
    > >> doing a simple search of all cells to determine if a certain value

    exists
    > > in
    > >> any of the workbooks.
    > >>
    > >> Any help?
    > >>
    > >>

    > >
    > >

    >
    >




  11. #11
    scott
    Guest

    Re: Loop Through All Open Workbooks

    i ran your code and it doesn't find a particular cell or give any error. can
    you try again?


    "Bob Phillips" <[email protected]> wrote in message
    news:%[email protected]...
    >
    > For Each wb In Application.Workbooks
    > If Application.CountIf(wb.Worksheets(1).Cells,"myValue) > 1 Then
    > MsgBox "Found in " & wb.Name
    > End If
    > Next wb
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "scott" <[email protected]> wrote in message
    > news:[email protected]...
    >> I'm trying to find an example of looping through all open workbooks and
    >> doing a simple search of all cells to determine if a certain value exists

    > in
    >> any of the workbooks.
    >>
    >> Any help?
    >>
    >>

    >
    >




  12. #12
    Tom Ogilvy
    Guest

    Re: Loop Through All Open Workbooks

    You have a solution that does that.

    --
    Regards,
    Tom Ogilvy

    "scott" <[email protected]> wrote in message
    news:ex83TP%[email protected]...
    > i ran your code and it doesn't find a particular cell or give any error.

    can
    > you try again?
    >
    >
    > "Bob Phillips" <[email protected]> wrote in message
    > news:%[email protected]...
    > >
    > > For Each wb In Application.Workbooks
    > > If Application.CountIf(wb.Worksheets(1).Cells,"myValue) > 1 Then
    > > MsgBox "Found in " & wb.Name
    > > End If
    > > Next wb
    > >
    > > --
    > >
    > > HTH
    > >
    > > RP
    > > (remove nothere from the email address if mailing direct)
    > >
    > >
    > > "scott" <[email protected]> wrote in message
    > > news:[email protected]...
    > >> I'm trying to find an example of looping through all open workbooks and
    > >> doing a simple search of all cells to determine if a certain value

    exists
    > > in
    > >> any of the workbooks.
    > >>
    > >> Any help?
    > >>
    > >>

    > >
    > >

    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1