繁体   English   中英

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

[英]How to delete rows in excel if the cell in the first column isn't bold?

我在excel中有一个列表,大约有20000行和4列。 此excel表包含粗体名称,之后的列包含有关它们的信息。 在每个名称之后,有一些超出的信息占用了3行或4行,但它并不一致。 我需要遍历工作表并删除没有粗体名称的所有行。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM