在excel中,使用可視化的簡單操作方法,是很難根據(jù)顏色來篩選的,因此,我們只能使用VBA代碼來實(shí)現(xiàn)。
以下代碼的功能是:除首行外,將當(dāng)前單元格所在列數(shù)據(jù)與當(dāng)前單元格不同顏色的行隱藏起來,數(shù)據(jù)首行為標(biāo)題列。
如果你有其它的需求,請自行修改代碼。
Sub FilterColor()
Dim UseRow, AC
UseRow = Cells.SpecialCells(xlCellTypeLastCell).Row
If ActiveCell.Row > UseRow Then
MsgBox "超出范圍,請選擇有數(shù)據(jù)或有意思的單元格!", vbExclamation, "錯(cuò)誤"
Else
AC = ActiveCell.Column
Cells.EntireRow.Hidden = False
For i = 2 To UseRow
If Cells(i, AC).Interior.ColorIndex <> ActiveCell.Interior.ColorIndex Then
Cells(i, AC).EntireRow.Hidden = True
End If
Next
End If
End Sub
新聞熱點(diǎn)
疑難解答
圖片精選