Find if a range exists?

tony.reynolds

Board Regular
Joined
Jul 8, 2010
Messages
97
hello all,

In my code i need to find if a range exists in my workbook and msgbox"yes"if yes and "no"if no!

i have at the moment a code that results in an error if it dosnt exist (so Im using on error goto statement) but that seems a bit crude

Any help would be appreciated!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Code:
Sub F()

    With Worksheets(1).Cells
        If Not .Find(What:="A") Is Nothing Then
            MsgBox "Found!"
        Else
            MsgBox "Not found!"
        End If
    End With

End Sub
 
Upvote 0
If you want to check for the existence of a named range try

Code:
Function NameExists(theName As String) As Boolean
Dim S As String
On Error GoTo EndFunction
S = ThisWorkbook.Names(theName).RefersTo
NameExists = True
Exit Function
EndFunction:
NameExists = False
End Function
 
Upvote 0
Code:
Sub F()
 
    With Worksheets(1).Cells
        If Not .Find(What:="A") Is Nothing Then
            MsgBox "Found!"
        Else
            MsgBox "Not found!"
        End If
    End With
 
End Sub

This finds out if the cell value in the worksheet exists but i want to find out if a range exists..

Like

Code:
if Range("ABC") .exists then
Msgbox"found"
Else
msgbox"not found"
 
Upvote 0
Incorrect question. You should say "named range" and not "range".
 
Upvote 0

Forum statistics

Threads
1,217,414
Messages
6,136,497
Members
450,016
Latest member
murarj

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