Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Run macro on all worksheets within workbook

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Run macro on all worksheets within workbook

Sub RowHighlight()
Dim DataRng As Range
Dim LastRow As Long
Dim cell As Range
Dim sh as Worksheet
'LastRow = Cells(Rows.Count, "A").End(xlUp).Row
for each sh in ActiveWorkbook.worksheets
sh.Activate
Set DataRng = Range("A3:A7")
For Each cell In DataRng
If cell.Value = " Date" Then
cell.EntireRow.Interior.ColorIndex = 3
End If
Next cell
Next
End Sub

You never use LastRow. Do you want the range determined by Lastrow

Sub RowHighlight()
Dim DataRng As Range
Dim LastRow As Long
Dim cell As Range
Dim sh as Worksheet
for each sh in ActiveWorkbook.worksheets
sh.Activate
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Set DataRng = Range("A3:A" & LastRow)
For Each cell In DataRng
If cell.Value = " Date" Then
cell.EntireRow.Interior.ColorIndex = 3
End If
Next cell
Next
End Sub

--
Regards,
Tom Ogilvy


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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run macro on all worksheets within workbook

I see some good code replies. However, all you're doing
is setting a row's color to red if the cell in A contains
the text " Date"
Seems to me that all yuo need to do is set a conditional
format on all the sheets.
First select all the sheets. Make sure the tabs are
visible, slect the first sheet, hold down shift & select
the last sheet.
Now slecty all the cells by clicking the 'cell' above
the '1' row and left of the 'A' column. Click
Format/Conditional Formatting , change to Formula Is and
enter
=($A1=" Date")
set the format to the Patter required.
Note that A1 must be the 'active' cell.

Any row in any sheet where the cell in column A is '
Date' will be red.

Patrick Molloy


-----Original Message-----
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
.

Reply
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
Combine worksheets in multiple workbook in one workbook with a macro Sam Commar Excel Discussion (Misc queries) 2 April 2nd 09 01:09 PM
Apply Macro to all worksheets in a workbook except one Carrie_Loos via OfficeKB.com Excel Discussion (Misc queries) 5 January 15th 09 10:03 PM
Macro to paste worksheets in another workbook [email protected] Excel Discussion (Misc queries) 0 March 28th 07 02:13 PM
Running Same macro in 250 Worksheets in Same Workbook halem2 Excel Worksheet Functions 3 March 24th 06 08:51 AM
Applying same macro to all worksheets in workbook [email protected] Excel Discussion (Misc queries) 2 October 19th 05 11:25 PM


All times are GMT +1. The time now is 06:34 PM.

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

About Us

"It's about Microsoft Excel"