Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 76
Default Formula Find Issue

Hello from Steved

Below Opens all files and closes in the directory which
is working correctly, but I would like it stay open when
2201 is found as at this time it opens and closes all
files. Help please I am Close.

Set FoundCell = WB.Worksheets(1).Cells.Find(what:=2201)

Thankyou.

Sub Test2()
Dim FName As String
Dim FoundCell As Range
Dim WB As Workbook
ChDrive C: '<<< CHANGE
ChDir "C:\Wtt" '<<< CHANGE
FName = Dir("*.xls")
Do Until FName = ""
Set WB = Workbooks.Open(FName)
Set FoundCell = WB.Worksheets(1).Cells.Find
(what:=2201)
If Not FoundCell Is Nothing Then
' do something with FoundCell
Else
' not found
End If
WB.Close SaveChanges:=True ' or False
FName = Dir()
Loop
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Formula Find Issue

Untested:

Sub Test2()
Dim FName As String
Dim FoundCell As Range
Dim WB As Workbook
ChDrive "C:" '<<< CHANGE
ChDir "C:\Wtt" '<<< CHANGE
FName = Dir("*.xls")
Do Until FName = ""
Set WB = Workbooks.Open(FName)
Set FoundCell = WB.Worksheets(1).Cells.Find(what:=2201)
If Not FoundCell Is Nothing Then
' do something with FoundCell
Else
WB.Close SaveChanges:=True ' or False
End If
FName = Dir()
Loop
End Sub

I just moved the .close into the Else portion of your If statement.

Well, and added quotation marks around your ChDrive drive letter.

Steved wrote:

Hello from Steved

Below Opens all files and closes in the directory which
is working correctly, but I would like it stay open when
2201 is found as at this time it opens and closes all
files. Help please I am Close.

Set FoundCell = WB.Worksheets(1).Cells.Find(what:=2201)

Thankyou.

Sub Test2()
Dim FName As String
Dim FoundCell As Range
Dim WB As Workbook
ChDrive C: '<<< CHANGE
ChDir "C:\Wtt" '<<< CHANGE
FName = Dir("*.xls")
Do Until FName = ""
Set WB = Workbooks.Open(FName)
Set FoundCell = WB.Worksheets(1).Cells.Find
(what:=2201)
If Not FoundCell Is Nothing Then
' do something with FoundCell
Else
' not found
End If
WB.Close SaveChanges:=True ' or False
FName = Dir()
Loop
End Sub


--

Dave Peterson

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
Issue with Find Farooq Sheri Excel Discussion (Misc queries) 5 October 13th 09 09:52 AM
FIND & REPLACE ISSUE William Excel Discussion (Misc queries) 6 September 2nd 09 02:45 PM
find and replace issue in macro ben New Users to Excel 2 December 21st 08 11:50 PM
Find Issue (Menu Find) PatK Excel Discussion (Misc queries) 4 December 3rd 07 04:51 PM
Excel find and replace issue buddyorliz Excel Discussion (Misc queries) 2 June 4th 05 04:14 PM


All times are GMT +1. The time now is 09:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"