答案 0 :(得分:0)
您可以这样做:
Public Sub DeleteAllRowsWithNoHighlitedCells()
Dim iRow As Long
Dim lastColumn As Long
Dim aktRow As Range
Dim owsh As Worksheet
Set owsh = ActiveSheet
iRow = 1
lastColumn = 7
Do Until owsh.Cells(iRow, 1) = ""
Set aktRow = owsh.Range(Cells(iRow, 1), Cells(iRow, lastColumn))
If Not AktRowHasHighlightedCells(aktRow) Then
owsh.Rows(aktRow.Row).Delete
iRow = iRow - 1
End If
iRow = iRow + 1
Loop
结束子
私有函数AktRowHasHighlightedCells(ByVal aktRow作为范围)为布尔值 Dikt aktcell作为变体
For Each aktcell In aktRow.Cells
If aktcell.Interior.ColorIndex = 3 Then
AktRowHasHighlightedCells = True
Exit Function
End If
Next aktcell
AktRowHasHighlightedCells = False
结束功能
解释我的意思。首先,您必须创建一个Button,并将 DeleteAllRowsWithNoHiHiglitedCells -过程放置在Click-Event后面。然后检查直到每行的Column1不为空,才检查从column1到lastColumn的所选行中的每个单元格(您必须定义,或者也可以通过VBA获取lastusedColumn)是否为Interior.Colorindex = 3(硬编码为红色)函数 AktRowHasHighlightedCells 为false,将删除该行,并减少rowCounter。