我在excel中有一个列表,大约有20000行和4列。此excel表包含粗体名称,之后的列包含有关它们的信息。在每个名称之后,有一些超出的信息占用了3行或4行,但它并不一致。我需要浏览工作表并删除没有粗体名称的所有行。
答案 0 :(得分:1)
您需要创建一个宏来查找当前工作表中有多少行,然后遍历工作表底部的行到顶部检查以查看第一个上的Font.Bold
属性该行的列设置为false。如果是这样,您删除该行。
以下适用于我:
Sub DeleteUnboldRows()
Dim lastRow As Long
Dim currentRow As Long
'Select All the rows in the active worksheet
lastRow = ActiveSheet.UsedRange.Rows.Count
' Iterate through each row from the bottom to the top.
' If we go the other way rows will get skipped as we delete unbolded rows!
For currentRow = lastRow To 1 Step -1
'Look at the cell in the first column of the current row
' if the font is not bolded delete the row
If ActiveSheet.Rows(currentRow).Columns(1).Font.Bold = False Then
ActiveSheet.Rows(currentRow).Delete
End If
Next currentRow
End Sub
以下是Bold
属性的参考:http://msdn.microsoft.com/en-us/library/office/aa224034%28v=office.11%29.aspx
答案 1 :(得分:1)
Sub deleteNonBolded()
Dim cell As Range
Dim selectRange As Range
For Each cell In Intersect(ActiveSheet.Range("A:A"), ActiveSheet.UsedRange)
If (cell.Font.Bold = False) Then
If selectRange Is Nothing Then
Set selectRange = cell
Else
Set selectRange = Union(cell, selectRange)
End If
End If
Next cell
selectRange.EntireRow.Delete
End Sub