我是 VBA 编程的新手。我想
- 搜索工作表,在第 6 行找到“N”或“TR”
- 然后,对于“N”或“TR”列中的每个单元格
- 如果所有单元格均为空白,则删除/隐藏该列
- 如果单元格不是空白的,突出显示空白的单元格
这听起来很简单,但我认为它需要两个 for 循环。
Sub checkandhide()
Set r = Range("6:6")
Rows("7:7").Select
For Each Cell In r
Selection.Find(What:="N", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, MatchByte:=False, SearchFormat:=False).Activate
'search for N
Application.Run "hidecolumn"
Next
End Sub
Sub hidecolumn()
Dim target As Range
Dim dwn As Range
Set dwn = Range(ActiveCell.End(xlDown).Address)
ActiveCell.Select
ActiveCell.Offset(6, 0).Select
For Each Cell In dwn
If Cell.Text = "" Then Columns.Delete
Next
End Sub