Determine if Cell with Specific Text is Visible in a Range Using VBA

jewkes6000

Board Regular
Joined
Mar 25, 2020
Messages
60
Office Version
  1. 365
Platform
  1. Windows
I'm trying to simply find out if a cell with specific text exists in a range. Here is the code I've tried, but it will only return a false argument.

VBA Code:
Private Sub UserForm_Initialize()
    Dim rgFound As Range
    Set rgFound = Range("O3:JA3").Find("Base CRX")
    If rgFound = Hidden Then MsgBox ("True")
  
    MsgBox ("False")

End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Your question is not entirely clear. Does this do what you are looking for?
VBA Code:
Private Sub UserForm_Initialize()
  Dim Cell As Range, Found As Boolean
  For Each Cell In Range("O3:JA3")
    If Not Cell.EntireColumn.Hidden And Cell.Value = "Base CRX" Then
      Found = True
      Exit For
    End If
  Next
  MsgBox Found
End Sub
 
Last edited:
Upvote 0
Solution
@Rick Rothstein - You hit the nail on the head. Your code worked. To be clear (at least I'll try to be clear), I'm trying to cycle through a range (O3:JA3) and find out if any cells containing the text "Base CRX" are hidden (along with the entire column which the text exists on). If this condition exists, then I need a true statement. This code does exactly that. Thank you!

Update - I did need to remove the "Not" to the If Not statement since that statement was what I was looking for.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,583
Members
449,089
Latest member
Motoracer88

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