根据标题清除所选行中的内容

  • 本文关键字:标题 清除 excel vba
  • 更新时间 :
  • 英文 :


我希望有一个宏,根据列标题删除特定列中的一系列行。更具体地说,假设在第 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

最新更新