我从一位同事那里收到了40MB的大量工作表,他对格式化一无所知。他没有隐藏网格线,而是用白色背景填充了网格线。我想找到所有具有白色背景的单元格,并将其更改为不填充,同时保留其他格式,例如货币和数字。
Sub White_to_no_fill_wb()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Cells.Interior.ColorIndex = 2 Then
ws.Cells.Interior.ColorIndex = 0
End If
Next ws
End Sub
这不会给我任何错误,但似乎也不起作用。
答案 0 :(得分:0)
遍历工作表,然后遍历使用范围内的单元格:
Sub RemoveWhiteFilling()
Dim ws As Worksheet
Dim myUsedRange As Range
Dim myCell As Range
For Each ws In ThisWorkbook.Worksheets
Set myUsedRange = ws.UsedRange
For Each myCell In myUsedRange
If myCell.Interior.ColorIndex = 2 Then
myCell.Interior.ColorIndex = 0
End If
Next myCell
Next ws
End Sub
答案 1 :(得分:0)
我认为,我们需要设置Range.Interior
Sub SetOK()
Dim iCnt As Integer, i As Integer, aCell As Range
iCnt = ActiveWorkbook.Worksheets.Count
For i = 1 To iCnt
Worksheets(i).Activate
For Each aCell In ActiveSheet.UsedRange
If aCell.Interior.Color = RGB(255, 255, 255) Then
With aCell.Interior
.Pattern = xlNone
End With
End If
Next aCell
Next i
End Sub