[英]Excel VBA, How to use the selection in a dropdown list on one sheet format(color) a range of cells on another sheet
[英]vba sheet color range Format
大家好,當我復制分組工作表時,電子表格中有 40 個選項卡,顏色會發生變化,
我寫了一個代碼只是為了更新受影響的工作表,但它不起作用,任何幫助將不勝感激。
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
嘗試通過更改以下內容來限定工作表的范圍:
Set r1 = Range("B1:E3")
Set r2 = Range("N1:P3")
到:
Set r1 = ws.Range("B1:E3")
Set r2 = ws.Range("N1:P3")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.