這裏有一個小腳本讓你開始。它將遍歷每行的每一列並檢查每個單元格的顏色。如果找到任何顏色,該行將被跳過。如果沒有發現有任何顏色的單元格,該行將被隱藏。換句話說,所有全白行將被隱藏。
CODE:
Public Sub HideUncoloredRows()
Dim startColumn As Integer
Dim startRow As Integer
Dim totalRows As Integer
Dim totalColumns As Integer
Dim currentColumn As Integer
Dim currentRow As Integer
Dim shouldHideRow As Integer
startColumn = 1 'column A
startRow = 1 'row 1
totalRows = Sheet2.Cells(Rows.Count, startColumn).End(xlUp).Row
For currentRow = totalRows To startRow Step -1
shouldHideRow = True
totalColumns = Sheet2.Cells(currentRow, Columns.Count).End(xlToLeft).Column
'for each column in the current row, check the cell color
For currentColumn = startColumn To totalColumns
'if any colored cell is found, don't hide the row and move on to next row
If Not Sheet2.Cells(currentRow, currentColumn).Interior.ColorIndex = -4142 Then
shouldHideRow = False
Exit For
End If
Next
If shouldHideRow Then
'drop into here if all cells in a row were white
Sheet2.Cells(currentRow, currentColumn).EntireRow.Hidden = True
End If
Next
End Sub
BEFORE
AFTER
來源
2013-03-27 13:14:46
Sam
嘗試檢查這..這是很難的question..http的://www.mrexcel.com/forum/excel-questions/84136-need-visual-basic-applications-hide-rows-have-yellow-fill。 html – Kasnady 2013-03-27 08:33:03