LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Is this a bug?

OK Ake, I tried it exactly as you described. Manually named the cell.
Manually entered the value. Then called the cell from the two macros. No
bug.

Sub Macro1()
Dim test As Variant
test = [Elmo]
MsgBox test
Macro2
End Sub

Sub Macro2()
Dim test As Variant
test = [Elmo]
MsgBox test
End Sub

Elmo is cell name and "Pass or Fail" is cell.value. I get Pass or Fail in
both MsgBox.

"Gary''s Student" wrote:

Maybe just the syntax. Remember that NamedCell is just a string. The
following does work:


Sub ake()
Dim test1 As String, test2 As String
Range("NamedCell").Value = "Contents"
test1 = Range("NamedCell").Address
test2 = Range("NamedCell").Value
MsgBox (test1)
MsgBox (test2)
Call ake2
End Sub

Sub ake2()
test1 = Range("NamedCell").Address
test2 = Range("NamedCell").Value
MsgBox (test1)
MsgBox (test2)
End Sub

Range("A38")
and
Range("NamedCell")

are equivalent
--
Gary's Student


"Ake" wrote:

Hi there,

I came across an inconsistency while coding the other day. I could easily
avoid it, so this is not the issue today. But, yet, I am curious by nature.
Is there some natural explanation, or have I come across a bug?

In its simplest form it works like this.
1. In a sheet (not in a macro) I name a cell to, say, NamedCell (say =$A$38).
2. I start a macro (singlestepping) and eventually I do
[NamedCell]="Contents", and sure enough, the contents appear in the cell
"A38".
3. As a check I do test=[NamedCell] and the contents are returned as expected
4. From within the first macro I immediately thereafter execute a second macro
5. In the second macro I immediately do test=[NamedCell], but both variables
are then declared empty. How come?

If this was a reference to a local variable, it is only proper that the
second macro does not know about it. But this is a reference to a named cell
in a sheet in a common work book- so all macros in that work book should have
access to it, I trust. (No other code is involved - not even declarations ;-)

Regards / Ake

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"