在VBA for Excel中查找所有粗体斜体

在VBA for Excel中查找所有粗体斜体,excel,vba,Excel,Vba,我试图在excel宏中查找并删除所有包含粗体斜体(即标题)的行 以下是我所拥有的: Sub CLEARHEAD() With Application.FindFormat.Font .Bold = True .Italic = True End With x = ActiveSheet.UsedRange.Rows.Count With Range(Cells(1, 1), Cells(x, 1)) Set i = .Find(What:="*", SearchFormat:=T

我试图在excel宏中查找并删除所有包含粗体斜体(即标题)的行

以下是我所拥有的:

Sub CLEARHEAD()
With Application.FindFormat.Font
    .Bold = True
    .Italic = True
End With
x = ActiveSheet.UsedRange.Rows.Count
With Range(Cells(1, 1), Cells(x, 1))
Set i = .Find(What:="*", SearchFormat:=True)
    If Not i Is Nothing Then
    firstAddress = i.Address
    Do
        i.EntireRow.Delete
        Set i = .FindNext(i)
    Loop While Not i Is Nothing And i.Address <> firstAddress
    End If
End With
End Sub
Sub CLEARHEAD()
使用Application.FindFormat.Font
.Bold=正确
.Italic=True
以
x=ActiveSheet.UsedRange.Rows.Count
带范围(单元格(1,1),单元格(x,1))
集合i=.Find(内容:=“*”,搜索格式:=True)
如果不是,那么我什么都不是
firstAddress=i.地址
做
i、 EntireRow.Delete
集合i=.FindNext(i)
循环而非i为Nothing和i.Address firstAddress
如果结束
以
端接头

在该范围内似乎找不到任何内容,但在第一列中有大量内容。

我重新启动了excel,宏运行正常。我不知道是什么问题。虽然有一个小错误。我不得不将.FindNext(I)替换为.Find(What:=“*”,SearchFormat:=True)。而且firstAddress没有意义,应该在宏删除时删除