View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Correct way to use names defined globally in a workbook, in VBA

So see my answer.

--
Regards,
Tom Ogilvy


"packat" wrote in message
news:ppBBd.22020$rL3.19909@trnddc03...


Bob Phillips wrote:
"packat" wrote in message
news:ESABd.30813$h.15240@trnddc04...

- I have a range A1:A10 with name PayHr in sheet1.

- When I crate a sub Initialize() in sheet2:
Private Sub Initialize()
Set payRange = Me.Range("HrPay") 'payRange is
defined
globally on the top section.
Debug.Print myRange.Cells(1, 1)
End Sub

This produced a compiler error: Method or data member not
found.
However, the code works when I define HrPay in sheet2.


Because you Set payRange and then reference myRange?



:-) It was a typo. The code did refer to correct variable
name.




Take a look at
http://www.xldynamic.com/source/xld.Names.html