2014-06-24 48 views
0

我试图在电子表格上运行反向更新以从一系列单元格中删除所有格式。迭代通过单元格足够快,但是使内部引用显着减慢代码的速度。在excel中快速格式化单元格

Set Rng1 = ThisWorkbook.Worksheets(ws.Name).Range("A17:bb300") 
For Each c1 In Rng1 
    If c1.Interior.Pattern = xlSolid Then 
     With c1.Interior 
      .Pattern = xlNone 
      .TintAndShade = 0 
      .PatternTintAndShade = 0 
     End With 
    End If 
Next c1 

干杯

+0

如何关闭/开启屏幕更新? 'Application.ScreenUpdating = False'然后在代码中将其设置为'True'。 – L42

+1

你的问题说:_“...删除所有格式...”,但你的代码只清除几个格式属性。如果你想清除_all_格式,使用'Rng1.ClearFormats' –

回答

0

或者你也可以先确定所有单元格,然后一气呵成格式:

Dim Rng1 As Range, Rng2 As Range 
Set Rng1 = ThisWorkbook.Worksheets(ws.Name).Range("A17:bb300") 

For Each c1 In Rng1 
    If c1.Interior.Pattern = xlSolid Then 
     If Rng2 Is Nothing Then 
      Set Rng2 = c1 
     Else 
      Set Rng2 = Union(Rng2, c1) 
     End If 
    End If 
Next c1 

With Rng2.Interior 
    .Pattern = xlNone 
    .TintAndShade = 0 
    .PatternTintAndShade = 0 
End With