Hi everyone I have 40 tabs in a spreadsheet when I copy grouped sheets the color changes,
I have written a code only to update the affected sheets but its not working, any help would be appreciated.
Sub Color()
Application.ScreenUpdating = False
Application.Calculation = xlAutomatic
Application.DisplayAlerts = False
Dim ws As Worksheet
Dim ws1 As Worksheet
Dim r1 As Range
Dim r2 As Range
Dim rngs As Range
For Each ws In ActiveWorkbook.Sheets
If ws.Name <> "A" And ws.Name <> "B" And ws.Name <> "C" And _
ws.Name <> "D" And ws.Name <> "E" And ws.Name <> "F" Then
Set r1 = Range("B1:E3")
Set r2 = Range("N1:P3")
Set rngs = Union(r1, r2)
With rngs.Interior
.PatternColorIndex = xlAutomatic
.Color = 49407
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
Next ws
Application.ScreenUpdating = True
Application.Calculation = xlAutomatic
Application.DisplayAlerts = True
End Sub
Try qualifying the ranges with the sheet by changing this:
Set r1 = Range("B1:E3")
Set r2 = Range("N1:P3")
to:
Set r1 = ws.Range("B1:E3")
Set r2 = ws.Range("N1:P3")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.