2017-01-28 111 views
-1

大家好我有,當我複製分組表顏色變化的電子表格40級的標籤,VBA紙色範圍格式

我寫了一個代碼只更新受影響的表,但它不工作,任何幫助將是讚賞。

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 
+0

使用'選擇案例ws.Name'然後'案 「A」,」 B「,」C「,」D「,」E「,」F「,並在」Case Else「下寫這個邏輯。 –

回答

1

嘗試與板出線範圍通過改變這樣的:

Set r1 = Range("B1:E3") 
Set r2 = Range("N1:P3") 

到:

Set r1 = ws.Range("B1:E3") 
Set r2 = ws.Range("N1:P3") 
+0

這樣做的伎倆,我在 – user3287522

+0

謝謝shai之前拉我的頭髮,但我用Gath的推薦 – user3287522