Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default how to tell if a named range exists

hi all,

in vba - how do you tell if a named range exists?

and whats the easiest way to create a named range

now i am doing:

Dim l As Range
ActiveWorkbook.Names("LastUsed").Delete
l = .Cells(Cells.Rows.Count, "C").End(xlUp)(2)
ActiveWorkbook.Names.Add name:="LastUsed", _
RefersToR1C1:="='Customer Orders'!R" & l.Row & "C" & l.Column

is there a better way to do this?

tia

J
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default how to tell if a named range exists

Dim nme As Name

On Error Resume Next
Set nme = ActiveWorkbook.Names("holidays")
On Error GoTo 0
If Not nme Is Nothing Then
MsgBox "Name exists"
End If


Set l = .Cells(Cells.Rows.Count, "C").End(xlUp)(2)
Range("'Customer Orders'!" & l.Address).Name = "LastUsed"


--
HTH

Bob Phillips

"Gixxer_J_97" wrote in message
...
hi all,

in vba - how do you tell if a named range exists?

and whats the easiest way to create a named range

now i am doing:

Dim l As Range
ActiveWorkbook.Names("LastUsed").Delete
l = .Cells(Cells.Rows.Count, "C").End(xlUp)(2)
ActiveWorkbook.Names.Add name:="LastUsed", _
RefersToR1C1:="='Customer Orders'!R" & l.Row & "C" & l.Column

is there a better way to do this?

tia

J



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default how to tell if a named range exists

There is no reason to tell if it exists if you want to define it. If it
already exists, it will be replace. If you want to see if it exists before
using it

On error resume Next
set rng = Range("LastUsed")
On Error goto 0
if rng is nothing then
.Cells(rows.count,3).End(xlup)(2).Name = "LastUsed"
End if

but if that is the only reason to test, then just do

.Cells(rows.count,3).End(xlup)(2).Name = "LastUsed"

--
Regards,
Tom Ogilvy



"Gixxer_J_97" wrote in message
...
hi all,

in vba - how do you tell if a named range exists?

and whats the easiest way to create a named range

now i am doing:

Dim l As Range
ActiveWorkbook.Names("LastUsed").Delete
l = .Cells(Cells.Rows.Count, "C").End(xlUp)(2)
ActiveWorkbook.Names.Add name:="LastUsed", _
RefersToR1C1:="='Customer Orders'!R" & l.Row & "C" & l.Column

is there a better way to do this?

tia

J



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
how to lookup if value exists in a range of data? S.elhalaby Excel Worksheet Functions 3 May 5th 23 07:43 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
Check if a number exists in a range? gkaste Excel Discussion (Misc queries) 2 July 13th 05 08:00 PM
within a macro how can I suppress the warning pop "A file named xxxx.xls already exists in this location. Do you want to replace it?" Pete McCosh Excel Programming 0 April 2nd 04 04:51 PM
easy way to test if a Named Range exists Andrew Bauer Excel Programming 4 July 10th 03 07:32 PM


All times are GMT +1. The time now is 08:18 PM.

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

About Us

"It's about Microsoft Excel"