Named Cell test

G

Guest

How do I find out if a named cell exists or not from VB (if it doesn't exist
I will the redefine which I know how to do). Regards, Brett
 
G

Guest

Dim myRange as Range

Set myRange = Nothing
on error resume next
Set myRange = aws.range("TestName") 'Assumes it's a worksheet name
'or
'Set myRange = Range("TestName") 'assumes it's a workbook name
on error goto 0
if not myRange is nothing then
'The range exists
else
'The range does not exist
end if

HTH,
Barb Reinhardt
 
G

Guest

Thanks Barb. I started fooling around with a test in the sheet to give a
#ref! and then test for that in VB, but I think your solution will be much
more elegant! Regards, Brett.
 
G

Guest

you could try:

Sub test()
Dim rngTemp As Range

On Error Resume Next
Set rngTemp = Range("NameTest")
On Error GoTo 0

If rngTemp Is Nothing Then
MsgBox "Does not exist"
Else: MsgBox rngTemp.Address(, , , True)
End If


End Sub
 
G

Guest

Thanks JMB. I must be getting better at this - in the interim I came up with

If Range("last.account.test").Value = CVErr(xlErrRef) Then
Range("A27").End(xlDown).Select
ActiveWorkbook.Names.Add Name:="last.account", RefersToR1C1:=ActiveCell
End If

AND IT WORKS! Thanks for your help, Brett
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top