LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 395
Default XL2007 : variable value changes unexpectedly

I am pulling data from a grid and manipulating the numbers to interpolate map
points between the existing coordinate values.

Here is the entire sub (not including the two grids of source values from a
worksheet). The problem that I'm seeing is with the value for AvgYRights.
This value calculates correctly (140.5) up until the line I've marked below.
When that line executes, the value of AvgYDiff correctly calculates to -24.5.
However, when that line executes, it also resets the value of AvgYRights to
-24.5. As far as I can tell, that is the only variable that is unexpectedly
changed to a different value.

Are these reserved Excel names, or is there something else I'm not seeing
that would cause AvgYRights to suddenly recalculate?

Many thanks,
Keith

Sub TestShape()

'in map coordinates
SourceLat = 47.931
SourceLong = 122.04 '(minus)

'Source sheet of map coordinate values
XList = Sheet3.Range("B1:L1")
XArray = Sheet3.Range("B2:L7") '1 to 6 rows, 1 to 11 columns
YList = Sheet3.Range("A2:A7")
YArray = Sheet3.Range("B12:L17")

'Adjust the used values; map coordinate grid for USA is from 66,25 to 126,50
AdjLong = SourceLong - 66
AdjLat = SourceLat - 25

'Longitude is in increments of 6 on my map
LowerX = AdjLong \ 6
UpperX = LowerX + 1
RemainderX = AdjLong Mod 6
'Latitude is in increments of 5 on my map
LowerY = AdjLat \ 5
UpperY = LowerY + 1
RemainderY = AdjLat Mod 5

'Verified: gets the correct values from my worksheet grid of coordinates
XVal1 = XArray(11 - LowerX, 6 - LowerY) 'lower right
XVal2 = XArray(11 - UpperX, 6 - LowerY) 'upper right
XVal3 = XArray(11 - LowerX, 6 - UpperY) 'lower left
XVal4 = XArray(11 - UpperX, 6 - UpperY) ' upper left

YVal1 = YArray(11 - LowerX, 6 - LowerY) 'lower right
YVal2 = YArray(11 - UpperX, 6 - LowerY) 'upper right
YVal3 = YArray(11 - LowerX, 6 - UpperY) 'lower left
YVal4 = YArray(11 - UpperX, 6 - UpperY) ' upper left

'Start the actual calculations
AvgXUppers = (XVal2 + XVal4) * 0.5
AvgXLowers = (XVal1 + XVal3) * 0.5
AvgXDiff = AvgXUppers - AvgXLowers
AvgYRights = (YVal1 + YVal2) * 0.5 'correctly evaluates
AvgYLefts = (YVal3 + YVal4) * 0.5 'AvgYRights is still correct
'when this next line executes, AvgYRights is changed too!
AvgYDiff = AvgYLefts - AvgYRights

AvgXLefts = (XVal3 + XVal4) * 0.5
AvgXRights = (XVal1 + XVal2) * 0.5
AvgXDiff2 = AvgXUppers - AvgXLowers
AvgYUppers = (YVal2 + YVal4) * 0.5
AvgYLowers = (YVal1 + YVal3) * 0.5
AvgYDiff2 = AvgYLefts - AvgYRights

'more calculations will be added here

End Sub

 
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cell Format changes unexpectedly HappyDaddy Excel Discussion (Misc queries) 1 October 7th 09 04:28 PM
Excel quits unexpectedly Simon Brown Excel Worksheet Functions 1 May 4th 07 11:36 PM
Sub unexpectedly jumps to another sub Jeff Wright[_2_] Excel Programming 3 August 26th 06 01:48 PM
Sub Exits Unexpectedly Walker Excel Programming 4 July 25th 05 10:43 PM
data changes unexpectedly Helen N. New Users to Excel 8 December 16th 04 03:49 PM


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

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"