0

I'm trying to incorporate named ranges into my macro after reading an answer to this question.

As an example, I have named a variable using a range as below, with the same name.

 Dim ExampleName As String: ExampleName = Range("ExampleName").Value

This particular scenario works fine and as expected - I'm just worried that using the same name could cause hidden problems further down the line if I am trying to manipulate larger ranges or perform other operations, and can't find any sources which either confirm or deny this.

Does using the same name for a variable within a macro, and a named range, have the potential to cause errors in my code? Or is it perfectly safe?

sdunnim
  • 181
  • 13
  • 1
    It is safe. One is a "String" and the other is an "Object". However to avoid any confusion, it is better to give it unique names :) – Siddharth Rout Aug 08 '19 at 09:40
  • @SiddharthRout Thanks. Can I infer from your comment that any two variables can be given the same name, as long as they are `Dim`d to different variable types? (I would avoid this in practice as you suggest, simply curious) – sdunnim Aug 08 '19 at 09:43
  • Depends where exactly are you declaring them. Till the time they are not "visible" to each other, it will be ok. – Siddharth Rout Aug 08 '19 at 09:46

0 Answers0