View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] jmslab@xs4all.nl is offline
external usenet poster
 
Posts: 55
Default Macro to find/report text in several files at once needs translationfor finding colored cells on the same way

Dear people that are better in VBA then me :)

A period ago I'd got a macro to find a specific text in a few files and the macro reported then in a new file where and in which files/sheets/cells the text was found. Really (for me) a spectacular code that works very well and helps me out to find/report text quickly.

Now another question came up which needs to find/report on the same way as it is now with text, but then to report a specific color found in several files.

In below code the part;
Range("B2").Select '(In B2 the search text is registered, like "AA1234")
aay = Range("B2").Value

Should be like B2 = Color of the cell to search.

If somebody could rewrite the code so it works for colors identical as for text it would be great :)

regards, Johan


'---------------------------------------
Sub SearchFoldersFollowUp()
Dim aax
Dim aay

Dim fso As Object
Dim fld As Object
Dim strSearch As String
Dim strPath As String
Dim strFile As String
Dim wOut As Worksheet
Dim wbk As Workbook
Dim wks As Worksheet
Dim lRow As Long
Dim rFound As Range
Dim strFirstAddress As String

On Error GoTo ErrHandler
Application.ScreenUpdating = False


'File/Directory with the Searchtext
Windows("ExcelSearch.xlsm").Activate
Sheets("BasisSheet").Select
Range("B1").Select '(In B1 the path of the search files is registered, like "c:\apps\excelsearch")
aax = Range("B1").Value
Range("B2").Select '(In B2 the search text is registered, like "AA1234")
aay = Range("B2").Value

strPath = "" & aax
strSearch = "" & aay

Set wOut = Worksheets.Add
lRow = 1
With wOut
.Cells(lRow, 1) = "Workbook"
.Cells(lRow, 2) = "Worksheet"
.Cells(lRow, 3) = "Cell"
.Cells(lRow, 4) = "Text in Cell"
Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder(strPath)

strFile = Dir(strPath & "\*.xls*")
Do While strFile < ""
Set wbk = Workbooks.Open _
(Filename:=strPath & "\" & strFile, _
UpdateLinks:=0, _
ReadOnly:=True, _
AddToMRU:=False)

For Each wks In wbk.Worksheets
Set rFound = wks.UsedRange.Find(strSearch)
If Not rFound Is Nothing Then
strFirstAddress = rFound.Address
End If
Do
If rFound Is Nothing Then
Exit Do
Else
lRow = lRow + 1
.Cells(lRow, 1) = wbk.Name
.Cells(lRow, 2) = wks.Name
.Cells(lRow, 3) = rFound.Address
.Cells(lRow, 4) = rFound.Value
End If
Set rFound = wks.Cells.FindNext(After:=rFound)
Loop While strFirstAddress < rFound.Address
Next

wbk.Close (False)
strFile = Dir
Loop
.Columns("A:D").EntireColumn.AutoFit
End With
MsgBox "Done"

ExitHandler:
Set wOut = Nothing
Set wks = Nothing
Set wbk = Nothing
Set fld = Nothing
Set fso = Nothing
Application.ScreenUpdating = True
Exit Sub

ErrHandler:
MsgBox Err.Description, vbExclamation
Resume ExitHandler
End Sub

'------------------------------------