View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Run macro on all worksheets within workbook

Mark,

See following code.
All references to "LastRow" were removed.
Adding some error handling would be a good idea.

'----------------------------------------------------
Sub RowHighlight()
Dim WS As Worksheet
Dim DataRng As Range
Dim cell As Range

For Each WS In Worksheets
Set DataRng = WS.Range("A3:A7")
For Each cell In DataRng
If cell.Value = " Date" Then
cell.EntireRow.Interior.ColorIndex = 3
End If
Next ' cell
Next 'WS

Set cell = Nothing
Set DataRng = Nothing
Set WS = Nothing
End Sub
'--------------------------------------------

Regards,
Jim Cone
San Francisco, CA
"Marek Socha" wrote in message
om...
I have a simple macro that highlights entire row based on specific
value within specified range.
Sub RowHighlight()
Dim DataRng As Range
Dim LastRow As Long
Dim cell As Range
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Set DataRng = Range("A3:A7")
For Each cell In DataRng
If cell.Value = " Date" Then
cell.EntireRow.Interior.ColorIndex = 3
End If
Next cell
End Sub
My workbook has more than a 100 worksheets...it would be a pain to tab

through all of them and run this macro.
How do I make it run through all worksheets?
Any help would be greatly appreciated.
Thanks,
Mark