Iteration Level

  • Thread starter Thread starter Philosophaie
  • Start date Start date
P

Philosophaie

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
 
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
 
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
 
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?
 
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
 
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.
 
Back
Top