Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 如果第一列中的单元格为';t黑体?_Excel - Fatal编程技术网

Excel 如果第一列中的单元格为';t黑体?

Excel 如果第一列中的单元格为';t黑体?,excel,Excel,我在excel中有一个大约20000行4列的列表。此excel工作表包含粗体名称,后面的列包含有关这些名称的信息。每个名称后面都有一些多余的信息,占据了3行或4行,但并不一致。我需要遍历工作表并删除所有没有粗体名称的行。您需要创建一个宏,找出当前工作表中有多少行,然后从工作表的底部到顶部遍历这些行,检查行的第一列上的Font.bold属性是否正确设置为false。如果是,则删除该行 以下是我的作品: Sub DeleteUnboldRows() Dim lastRow As Long

我在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
属性的参考资料:

非常感谢您,它工作得非常好!我试图编辑我在网上找到的删除粗体行的其他代码,但我无法让它工作。
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