如果在G列中找到空单元格,此代码将删除整行。我需要做的是清除列A中的单元格,如果列中的单元格G是空白的。如果同一行中的另一个单元格为空,则清除行中的单元格
On Error Resume Next ' In case there are no blanks
Columns("G:G").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
ActiveSheet.UsedRange 'Resets UsedRange for Excel 97
如果在G列中找到空单元格,此代码将删除整行。我需要做的是清除列A中的单元格,如果列中的单元格G是空白的。如果同一行中的另一个单元格为空,则清除行中的单元格
On Error Resume Next ' In case there are no blanks
Columns("G:G").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
ActiveSheet.UsedRange 'Resets UsedRange for Excel 97
试试这个:
With Intersect(Columns("G:G"), ActiveSheet.UsedRange)
If WorksheetFunction.CountBlank(.Cells) > 0 Then
.SpecialCells(xlCellTypeBlanks).Offset(, -6).ClearContents
End If
End With
试试这个。
Columns("G:G").SpecialCells(xlCellTypeBlanks).Offset(0,-6).ClearContents
像这样:
On Error Resume Next ' In case there are no blanks
Columns("G:G").SpecialCells(xlCellTypeBlanks).Offset(, -6) = ""
如果你要诉诸错误处理(出错时继续下一步),不要忘了之后重置(On Error转到0) – Reafidy 2012-02-09 00:27:44
+1不错的使用COUNTBLANK而不是标准的错误检查 – brettdj 2012-02-09 00:37:13