Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default Need "grep" like function to search multiple workbooks

I have a directory with a large number of excel workbooks. I'd like to
be able to search each workbook and extract a complete row if that row
contains the search term I'm looking for. Ideally the row extracted
would be placed into a new worksheet along with the name of the file
that row came from. The unix grep command is the fucntionality I'd
like to emulate. Is there a way to do that with a macro or are there
other tools I could use on a PC to accomplish my goal?


John Keith

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Need "grep" like function to search multiple workbooks

You need to run a macro from excel because the files are not text like files
that can be run from grep. You need to open each file using filesearch and
then search each file using find. I listed below the VBA help examples for
each of these instructions

Set fs = Application.FileSearch
With fs
.LookIn = "C:\My Documents"
.FileName = "*.xls"
If .Execute 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With

-----------------------------------------------------

With Worksheets(1).Range("a1:a500")
Set c = .Find(2, lookin:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Value = 5
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With
---------------------------------------------------------------------------------------


"John Keith" wrote:

I have a directory with a large number of excel workbooks. I'd like to
be able to search each workbook and extract a complete row if that row
contains the search term I'm looking for. Ideally the row extracted
would be placed into a new worksheet along with the name of the file
that row came from. The unix grep command is the fucntionality I'd
like to emulate. Is there a way to do that with a macro or are there
other tools I could use on a PC to accomplish my goal?


John Keith


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
=IF(ISNUMBER(SEARCH("ELB",B2)),"Pipe") add more like "ELB" "FLG" MAHMOUD Excel Worksheet Functions 5 September 6th 09 06:04 PM
=IF(ISERROR(SEARCH("insurance",A125,1)),"","*") cynichromantique Excel Worksheet Functions 9 September 25th 08 09:49 PM
"minimize multiple excel workbooks on windows taskbar" NC programmer Excel Discussion (Misc queries) 4 April 17th 08 04:22 PM
Multiple "source" workbooks linked to single "destination" workboo DAVEJAY Excel Worksheet Functions 1 September 17th 07 05:33 PM
use variable in Workbooks("book1").Worksheets("sheet1").Range("a1" Luc[_3_] Excel Programming 2 September 28th 05 08:37 PM


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