Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default 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
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
Iteration Khalil[_2_] Excel Worksheet Functions 4 June 19th 09 08:21 PM
Procedure level array not recognised at module level Numskull Excel Programming 2 May 21st 08 01:52 PM
workbook level name vs worksheet level name clara Excel Programming 1 September 19th 07 02:32 PM
Using macro to convert single level BOM to Multi Level BOM andrew_chong Excel Programming 0 February 7th 06 08:57 PM
Why, when I create workbook-level name does it jump it to Sheet-level ? Charles Jordan Excel Programming 1 November 5th 03 08:43 PM


All times are GMT +1. The time now is 01:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"