LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Old October 19th 18, 05:24 AM posted to microsoft.public.excel.programming
external usenet poster
First recorded activity by ExcelBanter: Apr 2009
Posts: 55
Default Change a Search/report code for text into search/report color


I found a fantastic code on the web to search through several excel file to find/report specific registered text values. Realy amazing. It reports the filename, specific sheet and the cell in a separate list. Great !

The challange I had is to change this code in such way that it search/reports not textvalues but filled in colors. I want to report the datafields which are marked with the color red (vbRed).

Can somebody, who is more clever then me, re-write the part that is required and changes the code in working for color.
Thanks a lot.

regards, Johan

Sub SearchFolders()
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

'Change as desired
strPath = "c:\MyFolder"
strSearch = "Specific text"

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, _

For Each wks In wbk.Worksheets
Set rFound = wks.UsedRange.Find(strSearch)
If Not rFound Is Nothing Then
strFirstAddress = rFound.Address
End If
If rFound Is Nothing Then
Exit Do
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

wbk.Close (False)
strFile = Dir
End With
MsgBox "Done"

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

MsgBox Err.Description, vbExclamation
Resume ExitHandler
End Sub

  #2   Report Post  
Old October 21st 18, 06:27 AM posted to microsoft.public.excel.programming
external usenet poster
First recorded activity by ExcelBanter: Apr 2009
Posts: 55
Default Change a Search/report code for text into search/report color

Hello (again), I found a code that reports colored cells just I like to have (reporting the cell names). The request is how to combine or adapt this (if this is the way to do it) into the first mentioned part. The result should be reporting of the fields in the same way as the its reported the cells with the found/reported text (Filename/Sheetname/Cell).

It would be very great if somebody can create/change this for me. I'm struckling with this for many hours and tried everything, but.......

ps. Because I got an overflow error when running below macro,
I added a tempory part that select only the used cells.

regards, Johan


Sub SelectColoredCells()

'Tempory added this part.
'Select the area with used cells (otherwise you get a stack overflow error)

Dim FirstCell As Range, LastCell As Range
Set LastCell = Cells(Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row, _
Cells.Find(What:="*", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Column)
Set FirstCell = Cells(Cells.Find(What:="*", After:=LastCell, SearchOrder:=xlRows, _
SearchDirection:=xlNext, LookIn:=xlValues).Row, _
Cells.Find(What:="*", After:=LastCell, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, LookIn:=xlValues).Column)
Range(FirstCell, LastCell).Select

'Macro for finding/reporting cells with filled color

Dim rCell As Range
Dim lColor As Long
Dim rColored As Range

'Select the color by name (8 possible)
'vbBlack, vbBlue, vbGreen, vbCyan,
'vbRed, vbMagenta, vbYellow, vbWhite
lColor = vbRed

'If you prefer, you can use the RGB function
'to specify a color
'lColor = RGB(0, 0, 255)

Set rColored = Nothing
For Each rCell In Selection
If rCell.Interior.Color = lColor Then
If rColored Is Nothing Then
Set rColored = rCell
Set rColored = Union(rColored, rCell)
End If
End If
If rColored Is Nothing Then
MsgBox "No cells match the color"

MsgBox "Selected cells match the color:" & _
vbCrLf & rColored.Address

'Instead of reporting the colored cells in the meassagebox
'I want to reported them the same way as mentioned in earlier request.
'reporting the file/sheet/cell in the file with the macro thats run
'through files in a specific directory.

End If
Set rCell = Nothing
Set rColored = Nothing
End Sub

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
Auto search the worksheet name and use it in report nirmalar Excel Discussion (Misc queries) 0 November 2nd 10 09:08 AM
Search Files and Report Results in Date Range MMA-Helper Excel Programming 0 February 6th 09 08:11 PM
create a report and have a search funtion to find data JJ Excel Discussion (Misc queries) 1 September 20th 08 03:34 PM
Search and change text color or style only Tony S.[_2_] Excel Programming 17 February 18th 08 05:35 PM
Search for text, change font color John[_108_] Excel Programming 2 July 8th 05 02:52 PM

All times are GMT +1. The time now is 12:31 AM.

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

About Us

"It's about Microsoft Excel"


Copyright © 2017