如何删除Excel中的行如果第一列中的单元格不是粗体?

我在excel中有大约20000行和4列的列表。 这个excel表单包含粗体名称,之后的列有关于它们的信息。 在每个名字之后,有一些额外的信息占用3或4行,但是不一致。 我需要遍历表单并删除没有粗体名称的所有行。

您需要创build一个macros来查找当前工作表中有多less行,然后遍历从工作表底部的行到顶部的检查,以查看该行第一列的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

 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