I have a workbook with about 150 to 200 tabs (changes each month). Searching for a particular tab can be quite time consuming. I modified a vba code from another workbook to help highlight the tab(s) that I am looking for based on the name I entered in a range of cells. The code works for highlighting the tab. However, if I do a second or third round of searches, the original highlighted tabs from the first search are still there. I would like to modified the vba code to clear all tabs of all color before highlighting specific tab based on my new search. Could someone please help me with the vba code below. I bold the line I am having issues with in the code. I am new to vba. Thank you in advance for your time and assistance.
Sub Highlight_Tab()
Dim ws As Worksheet
Dim rng As Range
ws.Tab.ColorIndex = xlColorIndexNone
For Each rng In Sheets("Summary").Range("O35:O38")
For Each ws In ThisWorkbook.Sheets
If ws.Name = rng.Value Then
ws.Tab.ColorIndex = 4
End If
Next ws
Next rng
End Sub
Sub Highlight_Tab()
Dim ws As Worksheet
Dim rng As Range
ws.Tab.ColorIndex = xlColorIndexNone
For Each rng In Sheets("Summary").Range("O35:O38")
For Each ws In ThisWorkbook.Sheets
If ws.Name = rng.Value Then
ws.Tab.ColorIndex = 4
End If
Next ws
Next rng
End Sub
Last edited: