有人能告诉我如何在不清除第一行和G列的情况下清除工作表的内容吗?
答案 0 :(得分:1)
瞧!
Range("A2:F" & Rows.Count).ClearContents
Range("H2", Cells(Rows.Count, Columns.Count)).ClearContents
答案 1 :(得分:0)
您可以使用SpecialCells()方法风格仅对可见单元格进行操作(即ClearContents
),如下所示:
Sub main()
HideMyFavorites True '<--| hide your favorite rows/columns
Cells.SpecialCells(xlCellTypeVisible).ClearContents '<--| clear the content of "visible" cells only
HideMyFavorites False '<--| unhide your favorite rows/columns
End Sub
Sub HideMyFavorites(doHide As Boolean)
Columns(7).Hidden = doHide '<--| hide/unhide column "G" (whose column index of "7")
Rows(1).Hidden = doHide '<--| hide/unhide row "1"
End Sub