LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
sc sc is offline
external usenet poster
 
Posts: 28
Default Can't get the find statement to work correctly

I am using Excel 2002. I am wanting to open all .xls files in a directory
check to see if it contains a specific text and then paste the filename in a
cell if it contains that text. Everything is working except the file name is
being pasted in the cells even if the file does not contain the text.

I have used some code I got from the internet to loop through all of the
files and open them and the paste all the files names in cells.

Here is the code I added:
With mybook.Worksheets(1)
Set c = .Find("Adam")
End With
If c = "Adam" Then


Here is all of the code put together:
'now we can open the files in the array MyFiles to do what we want
On Error GoTo CleanUp
Application.ScreenUpdating = False

Set basebook = ThisWorkbook

'clear all cells on the first sheet
basebook.Worksheets(1).Cells.Clear

'start row for the info from the first file
rnum = 1
'loop through all files in the array (MyFiles)
If Fnum 0 Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)
Set mybook = Workbooks.Open(MyFiles(Fnum))

Set sourceRange = mybook.Worksheets(1).Range("a1:c1")
SourceRcount = sourceRange.Rows.Count
Set destrange = basebook.Worksheets(1).Range("A" & rnum)

'This will add the workbook name in column D if you want
basebook.Worksheets(1).Cells(rnum, "D").Value = MyFiles(Fnum)

With mybook.Worksheets(1)
Set c = .Find("Adam")
End With
If c = "Adam" Then
sourceRange.Copy destrange
End If
rnum = rnum + SourceRcount



mybook.Close savechanges:=False
Next Fnum
End If
CleanUp:
Application.ScreenUpdating = False

Any help would be appreciated.

 
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
SMALL function seems not to work correctly hdf Excel Worksheet Functions 13 February 16th 08 02:38 PM
Sorting numbers doesn't work correctly GrammyEmmy New Users to Excel 8 June 25th 06 11:45 PM
How do I get Auto-Fit to work correctly? Mickey Dunne Excel Worksheet Functions 0 May 11th 06 01:47 AM
custom filter does not work correctly RJ Excel Discussion (Misc queries) 1 September 9th 05 07:34 PM
RunAutoMacros does not work correctly from vbscript! Juha Vehvilainen Excel Programming 2 January 3rd 04 02:11 AM


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