简体   繁体   中英

VBA clear data in sheet except first Row and Column G

谁能告诉我如何在不清除第一行和列G的情况下清除工作表的内容?

Voila!

Range("A2:F" & Rows.Count).ClearContents
Range("H2", Cells(Rows.Count, Columns.Count)).ClearContents

you could use a SpecialCells() method flavor to act (ie ClearContents ) on visible cells only, as follows:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM