View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
kkknie[_63_] kkknie[_63_] is offline
external usenet poster
 
Posts: 1
Default If then .... else

There is more than one way to do it, so here's my solution:

Code
-------------------
Sub test()

Dim n As Name
Dim strName As String
Dim bFound As Boolean

strName = "YourRangeName"
bFound = False

For Each n In ActiveWorkbook.Names
If n.Name = strName Then bFound = True
Next

If bFound = True Then
'If you want to remove the range name (but not the data) use
ActiveWorkbook.Names(strName).Delete

'If you want to delete the data use
Range(strName).Clear
'OR
Range(strName).Delete shift:=xlToLeft

Else

'Other code goes here

End If

End Su
-------------------

Post back with problems/questions.



--
Message posted from http://www.ExcelForum.com