Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Need an if statement to check if a certain named data range (call it
"testrange") exists or not? I am going to create it if it is not there, and if it is, I need to delete it. So have to check, otherwise will get run error. Thx. -- Boris |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Public Function NameExists(val As String)
Dim nme On Error Resume Next nme = ActiveWorkbook.Names(val) On Error GoTo 0 NameExists = (Not IsEmpty(nme)) End Function If NameExists("xyz" Then ... -- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "BorisS" wrote in message ... Need an if statement to check if a certain named data range (call it "testrange") exists or not? I am going to create it if it is not there, and if it is, I need to delete it. So have to check, otherwise will get run error. Thx. -- Boris |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
One way:
Public Sub ToggleTestRange() Const sNAME As String = "testrange" Dim nm As Name With ActiveWorkbook On Error Resume Next Set nm = .Names(sNAME) On Error GoTo 0 If nm Is Nothing Then .Names.Add Name:=sNAME, RefersTo:="some value" Else nm.Delete End If End With End Sub Or if you just want to create the name, but delete any existing copy before creating the new one: Public Sub MakeTestRange() Const sNAME As String = "testrange" With Application On Error Resume Next .Names(sNAME).Delete On Error GoTo 0 .Names.Add Name:=sNAME, RefersTo:="some value" End With End Sub In article , BorisS wrote: Need an if statement to check if a certain named data range (call it "testrange") exists or not? I am going to create it if it is not there, and if it is, I need to delete it. So have to check, otherwise will get run error. Thx. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
IF statement inside a SUMIF statement.... or alternative method | Excel Worksheet Functions | |||
Reconcile Bank statement & Credit card statement & accounting data | Excel Worksheet Functions | |||
Embedding an OR statement in an IF statement efficiently | Excel Discussion (Misc queries) | |||
Using an IF statement, or VLOOKUP statement | Excel Programming | |||
appending and IF statement to an existing IF statement | Excel Worksheet Functions |