我正在尝试生成一些VBA代码,该代码将在第一行的第一个单元格中查找包含列标题“New query”的列。然后应该删除每个中存在子字符串值''的所有行列的单元格。
这就是我的想法:
Set rng = Rows("1:1").Find(what:="New query", after:=Cells(1, 1), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext)
With Intersect(Sheets("Sheet1")
.Columns(rng.EntireColumn.Address))
.Replace "''", "#N/A", xlPart
.SpecialCells(xlConstants, xlErrors).EntireRow.Delete
End With
答案 0 :(得分:1)
您不希望使用Intersect
,这会导致问题。试试这个:
Set Rng = Rows("1:1").Find(what:="New query", after:=Cells(1, 1), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext)
With Rng.EntireColumn
.Replace "''", "#N/A", xlPart
.SpecialCells(xlConstants, xlErrors).EntireRow.Delete
End With