From: David on
Hi Again,

There are no passes taking place and the lines run one right after the
other. Which part of the 11 pages do you think would help?

Thanks,
--
David


"AB" wrote:

> I'd think that people here will ask for a bit more of your code to
> tell where the problem is.
> From the top of my head the first reason that would come to my mind is
> that somewhere in your code you're passing your variable (TotalValue)
> ByRef and not ByVal and that makes the two variables being pretty much
> one variable (when one changes, so does the other.
> .
>
From: ker_01 on
> There is a lot of code, what difference do you think it would make?

Since these two lines of code function properly by themselves (outside of
your code), posting just these two lines doesn't provide enough information
for anyone to provide anything more than guesses. You don't have to post all
of your code, just sections that are more likely to be relevant (like the sub
that contains these two lines, and if you have any code in worksheet_change
event, etc.). You also don't mention what version of Excel you are using,
which (at least for some problems) might help narrow down possible causes.

FWIW, I ran this sample code on both 2003 and 2007, and it worked fine in
both, returning the expected offset value.

Sub test_offset_problem()
ActiveCell = Sheet1.Range("A1")
TotalValue = ActiveCell.Offset(1, 1).Value
Debug.Print TotalValue
TargetTotal = ActiveCell.Offset(2, 2).Value
Debug.Print TargetTotal
End Sub




"David" wrote:

> Hi,
>
> There is a lot of code, what difference do you think it would make? These 2
> lines follow each other, one right after the other. The code is about 11
> pages when copied into Word. These lines appear about 5 pages into the Module.
>
> They are one statement right after the other:
> TotalValue = ActiveCell.Offset(16, 0).Value
> TargetTotal = ActiveCell.Offset(64, 0).Value
>
> The first line ends with a correct value. After the second line runs, it has
> a correct value in TargetTotal, but TotalValue has changed to the value of
> TargetTotal. In other words they are now both the same value.
>
> As I step through the code, which I have done several times, the opposite
> also happens:
>
> TotalValue = ActiveCell.Offset(16, 0).Value
> (Captures correct amount, but changes the value of TargetTotal, before the
> line is even run and puts the value of TotalValue in it)
>
> TargetTotal = ActiveCell.Offset(64, 0).Value
> (Changes the value of BOTH variable to the value of TargetTotal)
>
> It is not complicated code, but I sure can not explain it.
>
> Thanks,
> --
> David
>
>
> "EricG" wrote:
>
> > It might help if you shows us more of the code surrounding those two
> > statements...
> >
> > Eric
> >
> > "David" wrote:
> >
> > > Hi Group,
> > >
> > > I have something very strange happening, that I can not explain. I have 2
> > > variables:
> > >
> > > TotalValue = ActiveCell.Offset(16, 0).Value
> > > (Gets set to 102,000, which is a correct value.)
> > > TargetTotal = ActiveCell.Offset(64, 0).Value
> > > (Gets set to 35000, which is a correct value, BUT TotalValue becomes 35,000)
> > >
> > > I am not sure what I am missing in this process. Can anyone tell me why this
> > > would happened.
> > >
> > > Thanks,
> > > --
> > > David
From: ker_01 on
"AB" wrote:

> From the top of my head the first reason that would come to my mind is
> that somewhere in your code you're passing your variable (TotalValue)
> ByRef and not ByVal and that makes the two variables being pretty much
> one variable (when one changes, so does the other.

That would make sense...

From: AB on
People here are just trying to help you here. It's obviously abnormal
behaviour of your code and therefore there must be something in the
code.
Once again:
How are the
TotalValue
TargetTotal
dimensioned? (i.e. declared with Dim statment)
From: David on
Hi Again,

"passing your variable (TotalValue) ByRef and not ByVal" this is not
happening anywhere. The code is very linear with out any calls or passes.

Neither variable is Dimentioned, there are no Dim statements.

Thanks,

--
David


"ker_01" wrote:

> "AB" wrote:
>
> > From the top of my head the first reason that would come to my mind is
> > that somewhere in your code you're passing your variable (TotalValue)
> > ByRef and not ByVal and that makes the two variables being pretty much
> > one variable (when one changes, so does the other.
>
> That would make sense...
>