简体   繁体   English

vba表颜色范围格式

[英]vba sheet color range Format

Hi everyone I have 40 tabs in a spreadsheet when I copy grouped sheets the color changes,大家好,当我复制分组工作表时,电子表格中有 40 个选项卡,颜色会发生变化,

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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM