How To Run This Large Code On Seven Sheets Best Way?

aedctalk

Board Regular
Joined
Oct 9, 2010
Messages
156
Hello I have the below code. What i need to do is run it on seven sheets

FRI SAT SUN MON TUES WED THU

What i'm curious is .... is there some way i can run it on all seven sheets by just adding some code up on top?

Insted of copying the code 7 times and changing the sheet name each time (as it seems like it'd be really huge and clunkly if i did that.


Here is the code.. i'd like run on all seven sheets


Sheets("FRI").Select
Range("M78:M80").Select
Selection.Interior.ColorIndex = 2
Selection.Font.ColorIndex = 2
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Range("M80").Select
Selection.Copy
Range("M89").Select
ActiveSheet.Paste
Range("M98").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=9
Range("M107").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=9
Range("M116").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=9
Range("M125").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=9
Range("M134").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=9
Range("M143").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=9
Range("M152").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=9
Range("M161").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=6
Range("M170").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=9
Range("M179").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=9
Range("M188").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=9
Rows("193:193").RowHeight = 0
Rows("184:184").RowHeight = 0
Rows("175:175").RowHeight = 3
Rows("175:175").RowHeight = 0
ActiveWindow.SmallScroll Down:=-9
Rows("166:166").RowHeight = 0
ActiveWindow.SmallScroll Down:=-9
Rows("157:157").RowHeight = 0
ActiveWindow.SmallScroll Down:=-9
Rows("148:148").RowHeight = 0
ActiveWindow.SmallScroll Down:=-12
Rows("139:139").RowHeight = 0
ActiveWindow.SmallScroll Down:=-9
Rows("130:130").RowHeight = 0
ActiveWindow.SmallScroll Down:=-9
Rows("121:121").RowHeight = 0
ActiveWindow.SmallScroll Down:=-9
Rows("112:112").RowHeight = 0
ActiveWindow.SmallScroll Down:=-9
Rows("103:103").RowHeight = 0
ActiveWindow.SmallScroll Down:=-9
Rows("94:94").RowHeight = 0
ActiveWindow.SmallScroll Down:=-9
Rows("85:85").RowHeight = 0




Thank you! :)
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Try this:
Code:
Sub x()
    Dim wks         As Worksheet
 
    For Each wks In Worksheets
        With wks.Range("M78:M80")
            .Interior.ColorIndex = 2
            .Font.ColorIndex = 2
            .Borders.LineStyle = xlNone
        End With
 
        wks.Range("M80").Copy _
                Destination:=wks.Range("M89,M98,M107,M116,M125,M134,M143,M152,M161,M170,M179,M188")
        wks.Range("85:85,94:94,103:103,112:112,121:121,130:130,139:139,148:148,157:157,166:166,175:175,184:184,193:193").RowHeight = 0
    Next wks
End Sub
 
Upvote 0
Thanks! That looks super small compared to me having seven of the above! :)

However it looks to me like it runs on all worksheets in the workbook.

I have many other sheets in workbook.
So for that reason i'd need it only run on the

FRI SAT SUN MON TUE WED THU worksheets :/

Any other ideas would be much appreciated! Thanks soooooo much!
 
Upvote 0
Code:
Sub x()
    Dim wks         As Worksheet
 
    For Each wks In Worksheets
        If InStr(1, "|FRI|SAT|SUN|MON|TUE|WED|THU|", "|" & wks.Name & "|", vbTextCompare) Then

            With wks.Range("M78:M80")
                .Interior.ColorIndex = 2
                .Font.ColorIndex = 2
                .Borders.LineStyle = xlNone
            End With
 
            wks.Range("M80").Copy _
                    Destination:=wks.Range("M89,M98,M107,M116,M125,M134,M143,M152,M161,M170,M179,M188")
            wks.Range("85:85,94:94,103:103,112:112,121:121,130:130,139:139,148:148,157:157,166:166,175:175,184:184,193:193").RowHeight = 0
            End If
        Next wks
    End Sub
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,911
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top