Performance Excel-删除特定边框的更有效方法
我怎样才能使下面的代码更有效率,目前大约需要30秒才能完成 该代码将清除选定区域内具有白色背景的所有单元格,然后清除选定区域内的所有对角线边框 只有带有白色背景代码的透明单元格,它会立即完成,但当我添加删除边框代码时,它就变慢了Performance Excel-删除特定边框的更有效方法,performance,excel,border,vba,Performance,Excel,Border,Vba,我怎样才能使下面的代码更有效率,目前大约需要30秒才能完成 该代码将清除选定区域内具有白色背景的所有单元格,然后清除选定区域内的所有对角线边框 只有带有白色背景代码的透明单元格,它会立即完成,但当我添加删除边框代码时,它就变慢了 Sub ADULTClearOnly() Set sh2 = ThisWorkbook.Worksheets("ADULT Sign On Sheet") sh2.Select Cells.Range("B1:F756").Select For Each Ce
Sub ADULTClearOnly()
Set sh2 = ThisWorkbook.Worksheets("ADULT Sign On Sheet")
sh2.Select
Cells.Range("B1:F756").Select
For Each Cell In Selection
If Cell.Interior.Color = Excel.XlRgbColor.rgbWhite Then
Cell.Value = ""
End If
Next
Cells.Range("G1:AO757").Select
For Each Cell In Selection
If Cell.Borders(xlDiagonalUp).LineStyle = xlDiagonalUp Then
Cell.Borders(xlDiagonalUp).LineStyle = xlNone
End If
Next
End Sub
您的代码中有几个问题:
xlDiagonalUp
不是LineStyle
Cells.Range("G1:AO757").Select
For Each Cell In Selection
If Cell.Borders(xlDiagonalUp).LineStyle = xlDiagonalUp Then
Cell.Borders(xlDiagonalUp).LineStyle = xlNone
End If
Next
与
同样地
sh2.Select
Cells.Range("B1:F756").Select
For Each Cell In Selection
If Cell.Interior.Color = Excel.XlRgbColor.rgbWhite Then
Cell.Value = ""
End If
Next
可以简化为
For Each Cell In sh2.Range("B1:F756")
If Cell.Interior.Color = Excel.XlRgbColor.rgbWhite Then
Cell.ClearContents
End If
Next
谢谢,现在立即完成。
For Each Cell In sh2.Range("B1:F756")
If Cell.Interior.Color = Excel.XlRgbColor.rgbWhite Then
Cell.ClearContents
End If
Next