2014-01-24 36 views
0

我正试图在Excel宏中查找并删除包含粗体斜体(即标题)的所有行。在VBA for 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 

它看起来像什么范围内被发现,但也有一帮在第一列。

回答

0

我重新启动excel,宏运行良好。不知道问题是什么。虽然有一个小小的错误。我必须用.Find替换.FindNext(i)(What:=“*”,SearchFormat:= True)。第一个地址也没有意义,应该在宏删除时删除。