Loop Through All Open Workbooks

  • Thread starter Thread starter scott
  • Start date Start date
S

scott

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?
 
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
 
Thank you again for saving sanity.

Tom Ogilvy said:
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
 
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)
 
tom, can you look at the line

ans = msgbox "Continue to search",vbYesNo

it has a syntax error. thanks
 
can you correct syntax error in line

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


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


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
If Application.CountIf(wb.Worksheets(1).Cells,"myValue") > 1 Then


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
i ran your code and it doesn't find a particular cell or give any error. can
you try again?
 

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