ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Iteration Level (https://www.excelbanter.com/excel-programming/435602-iteration-level.html)

Philosophaie

Iteration Level
 
This is part odf my code from a Excel VBA program. They are all Julian Dates
around 2451544.5 days. For some reason it does not like PupA = A - Pup. I
think it is the iterations (k+2) then (k+1). Any suggestions?

Dim P, A, Pup, Adown, AP, PupA, PAdown As Double
For k = 1 To n
P = .Cells(k + 2, 5)
A = .Cells(k + 2, 10)
Pup = .Cells(k + 1, 5)
Adown = .Cells(k + 3, 10)
AP = P - A
PAdown = Adown - P
PupA = A - Pup
.Cells(k + 2, 12) = AP
.Cells(k + 2, 13) = PupA
.Cells(k + 2, 14) = PAdown
Next k

Sam Wilson

Iteration Level
 
Dim P, A, Pup, Adown, AP, PupA, PAdown As Double will declare PAdown as a
double, but the others as variants.

If the cell that gives A or Pup its value contains text etc the variant will
store it as text and A-Pup will give you an error. Try this instead:

Dim P as double, A as double, Pup as double ... PAdown As Double


"Philosophaie" wrote:

This is part odf my code from a Excel VBA program. They are all Julian Dates
around 2451544.5 days. For some reason it does not like PupA = A - Pup. I
think it is the iterations (k+2) then (k+1). Any suggestions?

Dim P, A, Pup, Adown, AP, PupA, PAdown As Double
For k = 1 To n
P = .Cells(k + 2, 5)
A = .Cells(k + 2, 10)
Pup = .Cells(k + 1, 5)
Adown = .Cells(k + 3, 10)
AP = P - A
PAdown = Adown - P
PupA = A - Pup
.Cells(k + 2, 12) = AP
.Cells(k + 2, 13) = PupA
.Cells(k + 2, 14) = PAdown
Next k


Patrick Molloy[_2_]

Iteration Level
 
not a lot to go on.
These aren't iterations but cell references. If there's an error, what
values are in the variables...they could be out of range

you show hte .Cells method but we don't see the WITH object

you declared PAdown as double, by by default, all your other variables are
VARIANT
this
Dim P, A, Pup, Adown, AP, PupA, PAdown As Double
should be
Dim P As Double, A As Double, Pup As Double, Adown As Double, AP As Double,
PupA As Double, PAdown As Double, k as Long
but no big deal





"Philosophaie" wrote:

This is part odf my code from a Excel VBA program. They are all Julian Dates
around 2451544.5 days. For some reason it does not like PupA = A - Pup. I
think it is the iterations (k+2) then (k+1). Any suggestions?

Dim P, A, Pup, Adown, AP, PupA, PAdown As Double
For k = 1 To n
P = .Cells(k + 2, 5)
A = .Cells(k + 2, 10)
Pup = .Cells(k + 1, 5)
Adown = .Cells(k + 3, 10)
AP = P - A
PAdown = Adown - P
PupA = A - Pup
.Cells(k + 2, 12) = AP
.Cells(k + 2, 13) = PupA
.Cells(k + 2, 14) = PAdown
Next k


Philosophaie

Iteration Level
 
Still not liking the subtraction of "PupA = A - Pup" or "PAdown = Adown - P"
when you take out "PupA". Still think it is the "Pup = .cells(k+1,10)" and
"Adown=.cells(k+1,10)" when "P = .Cells(k + 2, 5)" and "A = .Cells(k + 2,
10)". Is the k+1 vs k+2 fouling things up?



joel[_137_]

Iteration Level
 

Comment out any ON Error statements. this could be confusing the
problem.

Check Error trapping level

VBa menu : tools - OPtions - General Break On Error

I would set it to Break On All Errors.


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=149398


Sam Wilson

Iteration Level
 
Hmm. Maybe put the cursor in the line "PupA = A - Pup" and press F9 to insert
a break point,

then, run your code and when it hit's the break point examine the values of
your various variables.

Sam


"Philosophaie" wrote:

Still not liking the subtraction of "PupA = A - Pup" or "PAdown = Adown - P"
when you take out "PupA". Still think it is the "Pup = .cells(k+1,10)" and
"Adown=.cells(k+1,10)" when "P = .Cells(k + 2, 5)" and "A = .Cells(k + 2,
10)". Is the k+1 vs k+2 fouling things up?



Philosophaie

Iteration Level
 
No luck I still erroe and highlighted "PupA" with the red break point
underneath.

"Sam Wilson" wrote:

Hmm. Maybe put the cursor in the line "PupA = A - Pup" and press F9 to insert
a break point,

then, run your code and when it hit's the break point examine the values of
your various variables.

Sam


"Philosophaie" wrote:

Still not liking the subtraction of "PupA = A - Pup" or "PAdown = Adown - P"
when you take out "PupA". Still think it is the "Pup = .cells(k+1,10)" and
"Adown=.cells(k+1,10)" when "P = .Cells(k + 2, 5)" and "A = .Cells(k + 2,
10)". Is the k+1 vs k+2 fouling things up?



Patrick Molloy[_2_]

Iteration Level
 
what VALUES are in the variables, especially k


"Philosophaie" wrote:

No luck I still erroe and highlighted "PupA" with the red break point
underneath.

"Sam Wilson" wrote:

Hmm. Maybe put the cursor in the line "PupA = A - Pup" and press F9 to insert
a break point,

then, run your code and when it hit's the break point examine the values of
your various variables.

Sam


"Philosophaie" wrote:

Still not liking the subtraction of "PupA = A - Pup" or "PAdown = Adown - P"
when you take out "PupA". Still think it is the "Pup = .cells(k+1,10)" and
"Adown=.cells(k+1,10)" when "P = .Cells(k + 2, 5)" and "A = .Cells(k + 2,
10)". Is the k+1 vs k+2 fouling things up?



Philosophaie

Iteration Level
 
Tried a few things:

Added an array to all the variables.

added CDbl to all double dim.
Pup(k) = CDbl(.cells(k+2,10))

It keeps saying "Type Mismatch" error.

Sam Wilson

Iteration Level
 
Type mismatch is telling you that the content of .cells(k+2,10) is not a
number!


"Philosophaie" wrote:

Tried a few things:

Added an array to all the variables.

added CDbl to all double dim.
Pup(k) = CDbl(.cells(k+2,10))

It keeps saying "Type Mismatch" error.


Philosophaie

Iteration Level
 
Thanks that was it. There was text in the way.

"Sam Wilson" wrote:

Type mismatch is telling you that the content of .cells(k+2,10) is not a
number!


"Philosophaie" wrote:

Tried a few things:

Added an array to all the variables.

added CDbl to all double dim.
Pup(k) = CDbl(.cells(k+2,10))

It keeps saying "Type Mismatch" error.



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com