如果在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