#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 295
Default Named Cell test

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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,355
Default Named Cell test

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

"Brettjg" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 295
Default Named Cell test

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.

"Barb Reinhardt" wrote:

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

"Brettjg" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.misc
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Named Cell test

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


"Brettjg" wrote:

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

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 295
Default Named Cell test

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

"JMB" wrote:

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


"Brettjg" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Test if CELL is in RANGE Vaughan Excel Worksheet Functions 12 November 19th 06 02:48 PM
Calculate mean of test scores from rows of test answers RiotLoadTime Excel Discussion (Misc queries) 1 July 26th 06 05:14 PM
inserting a named range into new cells based on a named cell Peter S. Excel Discussion (Misc queries) 1 June 4th 06 03:53 AM
How can i test a cell for bold style in a cell (Excel 2003)? Mike A. Excel Worksheet Functions 2 March 6th 06 07:23 PM
How to test a cell to see if it is over a threshold? Grd New Users to Excel 4 December 5th 05 06:01 PM


All times are GMT +1. The time now is 02:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"