Iteration Level

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
 
S

Sam Wilson

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
 
P

Patrick Molloy

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
 
P

Philosophaie

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?
 
J

joel

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

Check Error trapping level

VBa menu : tools - OPtions - General Break On Error

I would set it to Break On All Errors
 
S

Sam Wilson

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
 
P

Philosophaie

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

Patrick Molloy

what VALUES are in the variables, especially k


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

Philosophaie

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top