Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
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? |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
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? |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
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? |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
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? |
#9
Posted to microsoft.public.excel.programming
|
|||
|
|||
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. |
#10
Posted to microsoft.public.excel.programming
|
|||
|
|||
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. |
#11
Posted to microsoft.public.excel.programming
|
|||
|
|||
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. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Iteration | Excel Worksheet Functions | |||
Procedure level array not recognised at module level | Excel Programming | |||
workbook level name vs worksheet level name | Excel Programming | |||
Using macro to convert single level BOM to Multi Level BOM | Excel Programming | |||
Why, when I create workbook-level name does it jump it to Sheet-level ? | Excel Programming |