我有以下代码:
Selection.Find(What:="4", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
Dim cl As Range, rTest As Range
Set rTest = Range("a1", Range("a1").End(xlToRight))
For Each cl In rTest
If Not cl.Value > 0 Then
cl.EntireColumn.Hidden = True
End If
Next cl
End Sub
在什么地方说什么= 4,我想搜索另一个工作表的范围(e15)。在一张纸上搜索E15的值,并在另一张纸的特定范围内查找。我已经完成了所有其他部分,但我不知道如何引用e15的值,这可以是4或任何其他数字。找到后,隐藏所有不是我特定值的列。非常感谢!
答案 0 :(得分:2)
你的行为应该如下
Dim f As Range
Set f = Selection.Find(What:=Worksheets("otherWorksheetName").Range("e15").Value, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)
If Not f Is Nothing Then
f.Activate '<--| what do you need this for?
Range("A1", Range("A1").End(xlToRight)).EntireColumn.Hidden = True '<--| hide all columns in wanted range
f.EntireColumn.Hidden = True '<--| unhide found range column
End If
您必须将“otherWorksheetName”更改为实际的“其他”工作表名称