View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson[_3_] Jim Thomlinson[_3_] is offline
external usenet poster
 
Posts: 983
Default Looking for Rod over in the corner...

In general you want to avoid repeating names as much as is possible in all
areas of what you are doing. It makes debugging and understaing a whole pile
more difficult. Once you have two different things with the same name then
you have to be more explicit in how you reference the items. In your case the
function or procedure would have to be referenced with where it came from in
order that it not be confused with the range name. Assuming the procedure was
in a module called Module1 you would have to call it by typing
Module1.MyProcedure so that the compiler would know exactly what you were
refering to.

That aside when you are reading your code and you refer to FilterRange it is
not always going to be obvious whether you are refering to the procedure or
the named range. Debugging becomes a nightmare when this happens.

HTH

"davegb" wrote:

I've been working on some spreadsheets with buttons/macros to apply
advanced filters. With a lot of help from here on some of it, they've
been working well.
Something very strange happened when I opened the workbook up this
morning. All the buttons started giving me the "Runtime error 1004" box
(by now, one of my personal favorites). I figured out that somehow,
XL2000 was confusing a named range in the spreadsheet and the name of a
macro used to create the named range, both called "FilterRange". I
didn't know this could be an issue. Does XL see both range names and
macro names as somehow the same? Is it a good idea in general to avoid
using the same name for a range and a macro?
When I changed the macro name to MFilterRange, the problem went away.
I should mention that the last thing I changed yesterday on this
workbook was to make all the filter criteria refer to an external cell
location for the criteria value so I could change that value in one
place in the worksheet and have everything that used that value change
too. I think somehow that doing this started the confusion. Or at
least, I can't think of what else I did that changed it.
Any suggestions?