VBA Cannot find in if cells are hidden. Even if ,xlformulas is used.

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Hi, below is the currentcode. It does not find if cells is hidden. How do i code to find it in hidden how.
I want to find exact match.
Thanks.

Code:
[/FONT]

[FONT=Courier New]Dim Found As Range, LR As Long, x As String
x = range("B1").value[/FONT]
[FONT=Courier New]With activesheet[/FONT]
[FONT=Courier New]    LR = .Range("E" & Rows.Count).End(xlUp).Row
      Set Found = .Range("E6:E" & LR).Find(what:=x, LookIn:=xlValues, _
        LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)
      If Not Found Is Nothing Then[/FONT]
[FONT=Courier New]          msgbox "kkkk"
      End If
End With
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
It works for me when changing xlValues to xlFormulas... Did you:

1. Have it work.
2. Hide the row and it doesn't work.
3. Change to xlFormulas and it *still* doesn't work?

It seems that since this is known to work when using xlFormulas, there must be some other issue at play.
 
Upvote 0
Tried with xlformulas too but wont work.
Entire e col is hidden.

Thanks again

Code:
[/FONT]
[FONT=Courier New]LR1 = .Range("E" & Rows.Count).End(xlUp).Row
      Set Found = .Range("E6:E" & LR1).Find(what:=x, LookIn:=xlFormulas, _
        LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)
 
Upvote 0
try looping through the cells?

i tried hiding the column and xlFormulas still works for me.
 
Last edited:
Upvote 0
I want it to be in a fastest way. I already have lots in my code execution process so thought loop might make the code execution even slower...:)

But I think there is a way out.

Thanks
 
Upvote 0
Pedie


  • application.screenupdating =false
  • unhide the column
  • search & find the value
  • do something
  • hide the column
  • turn screen updating back on
 
Upvote 0
Hi,
Here is another approach:
Rich (BB code):

Sub Test()
  Dim x As Range
  Set x = EvalFind([B1], [E:E]) ' or the same: Set x = EvalFind(Range("B1"), Range("E:E"))
  If x Is Nothing Then
    MsgBox [B1] & " is not found"
  Else
    MsgBox [B1] & " is found in " & x.Address
  End If
End Sub

Function EvalFind(What, Where As Range) As Range
  Dim i&, q$
  If VarType(What) = vbString Then q = """"
  On Error Resume Next
  i = Evaluate("MATCH(" & q & What & q & "," & Where.Address(External:=True) & ",0)")
  If i > 0 Then Set EvalFind = Where(i)
End Function
Regards,
 
Upvote 0
And the similar:

Rich (BB code):

Sub Test1()
  Dim x As Range
  Set x = WsFuncMatch([B1], [E:E]) ' or the same: Set x = WsFuncMatch(Range("B1"), Range("E:E"))
  If x Is Nothing Then
    MsgBox [B1] & " is not found"
  Else
    MsgBox [B1] & " is found in " & x.Address
  End If
End Sub

Function WsFuncMatch(What, Where As Range) As Range
  Dim i&
  On Error Resume Next
  i = WorksheetFunction.Match(What, Where, 0)
  If i Then Set WsFuncMatch = Where(i)
End Function
 
Upvote 0

Forum statistics

Threads
1,216,101
Messages
6,128,845
Members
449,471
Latest member
lachbee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top