Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Macro acting on all Sheets

I have a WB with 19 WS in it. I have a set of Macros (3 so far) which are
intended to work on each WS individually. They starts off similarly to this:

myCount = 0 'Counts the Rows in the inner loops
NewStartRow = 2 'Start Row of each set
myRowCount = 0 'Counts the Rows in the outer loop

With ActiveSheet
Set rngLastRow = .Cells(.UsedRange.Rows.Count,
..UsedRange.Columns.Count).EntireRow
End With

Do While NewStartRow <= rngLastRow.Row 'Check every row
If myRowCount rngLastRow.Row Then
Exit Do
End If

Set myCell = Cells(NewStartRow + myRowCount, 3) 'First time starts
in Row 2

When I run them I discover that they are each running on all 19 pages at the
same time. I just thought, there is some other code in the Macro that might
be the guilty party. It is this:

If mySubTotal < CurVal Then 'Highlight set where there is a
mis-match
Selection.End(xlToLeft).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(("A" & NewStartRow - varOffset), ("S" &
NewStartRow - 1)).Select
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
End If

Is the problem in that "Range(Selection...)" stuff?
--
Dave
Temping with Staffmark
in Rock Hill, SC
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Macro acting on all Sheets

Dave, I don't see anything in the posted code that would affect
more than the active sheet. You said there were three macros.
If you have one that has a section with something like:

For Each Sheet in ActiveWorkbook.Worksheets...

Then it could be calling the macro you posted and would run it
for each of the 19 worksheets. As for the selection stuff, see
below comments.

If mySubTotal < CurVal Then 'Highlight set where there is a
mis-match
Selection.End(xlToLeft).Select
Range(Selection, Selection.End(xlToRight)).Select

'The two rows above can be eliminated.
'They do nothing more that move the cursor from right to left
and back.

'The code below adds a color to a range interior and puts a
'thick border at the bottom of the cell

Range(("A" & NewStartRow - varOffset), ("S" &
NewStartRow - 1)).Select
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
End If


"Dave Birley" wrote:

I have a WB with 19 WS in it. I have a set of Macros (3 so far) which are
intended to work on each WS individually. They starts off similarly to this:

myCount = 0 'Counts the Rows in the inner loops
NewStartRow = 2 'Start Row of each set
myRowCount = 0 'Counts the Rows in the outer loop

With ActiveSheet
Set rngLastRow = .Cells(.UsedRange.Rows.Count,
.UsedRange.Columns.Count).EntireRow
End With

Do While NewStartRow <= rngLastRow.Row 'Check every row
If myRowCount rngLastRow.Row Then
Exit Do
End If

Set myCell = Cells(NewStartRow + myRowCount, 3) 'First time starts
in Row 2

When I run them I discover that they are each running on all 19 pages at the
same time. I just thought, there is some other code in the Macro that might
be the guilty party. It is this:

If mySubTotal < CurVal Then 'Highlight set where there is a
mis-match
Selection.End(xlToLeft).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(("A" & NewStartRow - varOffset), ("S" &
NewStartRow - 1)).Select
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
End If

Is the problem in that "Range(Selection...)" stuff?
--
Dave
Temping with Staffmark
in Rock Hill, SC

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Macro acting on all Sheets

Thanks for clarifying (and also for helping me to drop two un-needed rows of
code).

Programming, I have learned over the years, is a lot like genealogy.
Sometimes the negative information is as useful as the positive. It
eliminates unwarranted suspicions <g!
--
Dave
Temping with Staffmark
in Rock Hill, SC


"JLGWhiz" wrote:

Dave, I don't see anything in the posted code that would affect
more than the active sheet. You said there were three macros.
If you have one that has a section with something like:

For Each Sheet in ActiveWorkbook.Worksheets...

Then it could be calling the macro you posted and would run it
for each of the 19 worksheets. As for the selection stuff, see
below comments.

If mySubTotal < CurVal Then 'Highlight set where there is a
mis-match
Selection.End(xlToLeft).Select
Range(Selection, Selection.End(xlToRight)).Select

'The two rows above can be eliminated.
'They do nothing more that move the cursor from right to left
and back.

'The code below adds a color to a range interior and puts a
'thick border at the bottom of the cell

Range(("A" & NewStartRow - varOffset), ("S" &
NewStartRow - 1)).Select
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
End If


"Dave Birley" wrote:

I have a WB with 19 WS in it. I have a set of Macros (3 so far) which are
intended to work on each WS individually. They starts off similarly to this:

myCount = 0 'Counts the Rows in the inner loops
NewStartRow = 2 'Start Row of each set
myRowCount = 0 'Counts the Rows in the outer loop

With ActiveSheet
Set rngLastRow = .Cells(.UsedRange.Rows.Count,
.UsedRange.Columns.Count).EntireRow
End With

Do While NewStartRow <= rngLastRow.Row 'Check every row
If myRowCount rngLastRow.Row Then
Exit Do
End If

Set myCell = Cells(NewStartRow + myRowCount, 3) 'First time starts
in Row 2

When I run them I discover that they are each running on all 19 pages at the
same time. I just thought, there is some other code in the Macro that might
be the guilty party. It is this:

If mySubTotal < CurVal Then 'Highlight set where there is a
mis-match
Selection.End(xlToLeft).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(("A" & NewStartRow - varOffset), ("S" &
NewStartRow - 1)).Select
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
End If

Is the problem in that "Range(Selection...)" stuff?
--
Dave
Temping with Staffmark
in Rock Hill, SC

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
Excel acting up Good Excel Workbooks Now Acting Up Excel Discussion (Misc queries) 2 December 1st 09 11:02 PM
Help...my charts are acting up! Geoff Charts and Charting in Excel 2 May 9th 07 09:06 PM
Macros the same but not acting the same tahrah Excel Programming 0 January 9th 07 02:02 PM
ListBox/ComboBox Acting as Macro/Hyperlink Tool Phil H[_2_] Excel Programming 12 March 31st 06 12:48 PM
Macro for filter on protected workbook that works for all sheets, no matter what sheets are named? StargateFanFromWork[_3_] Excel Programming 6 January 26th 06 06:31 PM


All times are GMT +1. The time now is 10:11 PM.

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

About Us

"It's about Microsoft Excel"