简体   繁体   English

VBA清除工作表中的数据,但第一行和第G列除外

[英]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: 您可以使用SpecialCells()方法来ClearContents可见单元执行操作(即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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用excel VBA清除除第一行之外的整行数据 - Clear entire row data except the first row using excel VBA 清除除第一行和第一列之外的所有数据 - Clear All Data EXCEPT First Row and First Column 清除列数据,但第一个标题除外| Excel | VBA | - Clear Column Data except first Headers |Excel|VBA| 删除前两列中的值,但第一列中的值等于工作表VBA名称的行除外 - Remove values in first two columns except the row where a value in the first column equals the name of the sheet VBA 用当月VBA的日期填充行中的一系列单元格,然后保存数据并在下个月的第一天清除工作表 - Populating a range of cells in row with dates of the current month VBA, then save data and clear sheet at the first of the next month VBA 清除单元格范围内的内容,工作表 1 除外 - VBA clear content in cell range, except for sheet 1 在工作表1的G列中找到非零值,将该行中的列C的值返回到工作表2(VBA) - Find non zero value in column G on sheet 1, return value of Column C in that row to sheet 2 (VBA) VBA 将数据粘贴到第一个空行的列中 - VBA to paste data in column in first empty row 如果列中的行范围与另一工作表中的列的范围相匹配,则 VBA 会清除行中单元格的内容 - VBA clear contents from cells in row if range of rows in column match range from column in another sheet Excel VBA如果第一行包含单词“结束日期”,则将工作表1的粘贴列复制到工作表2 - Excel VBA Copy Paste column from sheet 1 to sheet 2 if first row countain the word “End Date”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM