我希望有一个宏,根据列标题删除特定列中的一系列行。更具体地说,假设在第 5 行标有"C"的任何列,我想通过循环遍历 B 到 CB 列(例如(来清除这些特定列的第 11 行到第 33 行的内容。谢谢!
样本:
Sub Hide_Columns_Containing_Value()
'Description: This macro will loop through a row and
'hide the column if the cell in row 1 of the column
'has the value of C.
'Author: Jon Acampora, Excel Campus
Dim c As Range
For Each c In Range("A5:CE5").Cells
If c.Value = "C" Then
c.EntireColumn.Hidden = True {{{<------would like to clear contents of rows 11 thru 33 instead of hide columns}}}
End If
Next c
End Sub
几个选项,这里有一个使用Intersect
:
Intersect(c.EntireColumn, Rows("11:33")).ClearContents