ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Named ranges disappearing in Excel 2007 (https://www.excelbanter.com/excel-programming/403089-named-ranges-disappearing-excel-2007-a.html)

Mike

Named ranges disappearing in Excel 2007
 
I have some named ranges (no more than 15) in a workbook and I am assigning
their values to string variables. For some reason my named ranges
are randomly disappearing after my code runs.

The syntax in VBA looks like this:

strDate = Worksheets("SheetName").Range("NamedRange1").Value

Any ideas?????


Bill Renaud

Named ranges disappearing in Excel 2007
 
Are you deleting the cells of the named range somewhere in your code? The
named range will refer to 'Worksheet Name'!#REF! after the delete, and will
be invalid the next time you try to use it.

You will have to step through all of your code to figure out where this is
happening.

You might consider including an error hander and doing it like this:

Public Sub Test()
Dim rngNamedRange As Range

On Error Resume Next

Set rngNamedRange = ThisWorkbook.Names("NamedRange").RefersToRange

If rngNamedRange Is Nothing _
Then
MsgBox "'NamedRange' has disappeared!", vbCritical + vbOKOnly
Else
'Continue processing.
End If
End Sub

--
Regards,
Bill Renaud




David J Richardson

Named ranges disappearing in Excel 2007
 
In article ,
Mike wrote:

I have some named ranges (no more than 15) in a workbook and I am
assigning their values to string variables. For some reason my named
ranges are randomly disappearing after my code runs.


I have seen this happen recently, but only once. I don't know whether
the disappearance was related to code running or not.

--
David J Richardson --
http://davidj.richardson.name/ - Dr Who articles/interviews/reviews
http://www.boomerang.org.au/ - Boomerang Association of Australia


All times are GMT +1. The time now is 04:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com