I would like to detect whether there’s any red cell in any sheet of an excel file (including the hidden sheet). If red cell exists in any sheet, I would like to get the sheet name and cell address to populate them in a summary report later.
Any advice on what is the best way to do this?
If it is macro, how should the script looks like?
Please try this macro…it will read all sheets and will write the sheetname and cell address in a separate sheet in the same file
Sub FindRedFillCells()
Dim ws As Worksheet
Dim destSheet As Worksheet
Dim cell As Range
Dim lastRow As Long
Set destSheet = ThisWorkbook.Sheets.Add(After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))
destSheet.Name = "RedFillCells"
destSheet.Range("A1").Value = "Sheet Name"
destSheet.Range("B1").Value = "Cell Address"
For Each ws In ThisWorkbook.Worksheets
For Each cell In ws.UsedRange.Cells
If cell.Interior.Color = RGB(255, 0, 0) Then
lastRow = destSheet.Cells(destSheet.Rows.Count, 1).End(xlUp).Row + 1
destSheet.Cells(lastRow, 1).Value = ws.Name
destSheet.Cells(lastRow, 2).Value = cell.Address
End If
Next cell
Next ws
End Sub
One small point, do you mind to advice how can I tailor the code to the below?
Instead of writing the summary of cell address in a new sheet of the same excel file, I would like to write the result in a specific excel file that I have created, the file is named as “Summary Table.xlxs”, under column D with below format
After running the macro read the sheet and store in dt (datatable variable) and then use the following to convert to string as you need and write to excel you need