#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Cells.find

I have a workbook with 5 sheets in. When I recorded a macro using Find all
worked well. But when I come to run the macro I get a run time error 91. This
is the Macro,
Sheets("ft mid - small cap").Select
Cells.Find(What:="al_", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=
_
False, SearchFormat:=False).Activate
I think that when the worksheet named is active it works fine, but I would like
to search the whole workbook, as later the What will change. I recall trying to
do this before and seem to remember using the 'with statement'. Please can
anybody advise.
Regards Robert
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Cells.find

Robert

Could you want something like :

Option Explicit

Sub FindInAllSheets()

Dim FindValue As String
Dim oSht As Worksheet
Dim FoundCell As Range
Dim FirstAddr As String

FindValue = "al_"

For Each oSht In ActiveWorkbook.Worksheets
With oSht.Cells
Set FoundCell = .Find(What:=FindValue, After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart,
SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False)
If Not FoundCell Is Nothing Then
FirstAddr = FoundCell.Address
Do
' your code here
Set FoundCell = .FindNext(FoundCell)
Loop While Not FoundCell Is Nothing And
FoundCell.Address < FirstAddr
End If
End With
Next 'oSht

End Sub


---
Message posted from http://www.ExcelForum.com/

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Cells.find

Thankyou for your advise.
Regards Robert
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
Need Cells.find to find first number in a row which is 8000 Kasper Excel Discussion (Misc queries) 9 December 15th 08 02:10 PM
how to find cells that refer to data in other cells in excel Aman Excel Discussion (Misc queries) 8 December 2nd 07 10:02 PM
from a group of cells.find average of cells containing values farm Excel Discussion (Misc queries) 1 December 21st 06 08:50 PM
sort spreadsheet, "merged cells" comes up. Find cells? Unmerge ? lowell Excel Discussion (Misc queries) 1 August 20th 06 09:10 AM
How to find multiple cells/replace whole cells w/data dcurylo Excel Discussion (Misc queries) 2 November 30th 05 08:06 PM


All times are GMT +1. The time now is 11:19 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"