【发布时间】:2019-10-04 00:38:33
【问题描述】:
我有一个表格(X x Y),其中随机单元格填充为红色(范围可以从列中填充的所有单元格到一些填充的单元格,再到列中未填充的单元格)。我想隐藏没有填充单元格的列。下面的代码查找填充为红色的单元格并隐藏整个列,无论是否有任何未填充的单元格。我想隐藏没有填充单元格的列在。
Dim cell As Range
For Each cell In Selection
If cell.Interior.Color = vbRed Then 'finds the filled in cells
Columns(cell.Column).EntireColumn.Hidden = True 'hides the column with filled in cells
End If
Next
提前谢谢你。
【问题讨论】:
-
当你说没有填充单元格的列时。你是什么意思?数据样本(截图会有所帮助)
-
[1.] 循环遍历表格的列[2.] 使用
Application.Worksheetfunction.CountA检查空白单元格。您也可以为此使用Application.WorksheetFunction.CountBlank[3.]隐藏列