[RESOLVED] Runtime Error 6 Overflow-VBForums
Results 1 to 4 of 4

Thread: [RESOLVED] Runtime Error 6 Overflow

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2010
    Posts
    30

    Resolved [RESOLVED] Runtime Error 6 Overflow

    I have the following code that keeps giving me a runtime error 6 "overflow". I have read that it is usually caused by too much information being processed a the same time, but I am not sure how to fix it.

    Any help would be appreciated.


    Code:
    For Each Cell In Sheets("CHLOROPHYLLS").Range("A12:A45")
    
       
       If IsEmpty(ActiveCell) = False Then
            Cell.Offset(0, 12).Value = (((11.85 * (Abs(Cell.Offset(0, 8).Value - Cell.Offset(0, 11).Value))) - _
            (1.54 * (Abs(Cell.Offset(0, 8).Value - Cell.Offset(0, 10).Value))) - (0.08 * (Abs _
            (Cell.Offset(0, 8).Value - Cell.Offset(0, 9).Value)))) * Cell.Offset(0, 7).Value) / (Cell.Offset(0, 5).Value / 1000)
            
        Else
          End If
            
      Next

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    19,827

    Re: Runtime Error 6 Overflow

    it means that the value returned from some part of your calculation is too large for the default TYPE that will contain the value

    break the calculation into sections to find which part is is returning the error
    also it may only be happening in certain cells, so you need to find which cells (values) cause the error

    try like
    vb Code:
    1. Dim tempval As Double
    2. tempval = Abs(cell.Offset(0, 8).Value - cell.Offset(0, 11).Value) - (1.54 * (Abs(cell.Offset(0, 8).Value - cell.Offset(0, 10).Value))) - (0.08 * (Abs(cell.Offset(0, 8).Value - cell.Offset(0, 9).Value)))
    3. tempval = tempval * 11.85
    4. tempval = tempval * cell.Offset(0, 7).Value
    5. tempval = tempval / cell.Offset(0, 5).Value
    6. tempval = tempval / 1000
    7. Cell.Offset(0, 12).Value = tempval
    find which line errors
    if the first line errors break it down further
    if need be change tempval to currency type
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2010
    Posts
    30

    Re: Runtime Error 6 Overflow

    WestConn1,

    Thank you for your help. I had to change the code a bit for it to calculate the way I wanted. The code below is what finally stopped the overflow issue.

    Code:
    For Each cell In Sheets("CHLOROPHYLLS").Range("A12:A45")
    
    cell.Select
    If IsEmpty(ActiveCell) = False Then
    Dim tempval As Double
    tempval = (11.85 * (Abs(cell.Offset(0, 8).Value - cell.Offset(0, 11).Value))) - _
    (1.54 * (Abs(cell.Offset(0, 8).Value - cell.Offset(0, 10).Value))) - _
    (0.08 * (Abs(cell.Offset(0, 8).Value - cell.Offset(0, 9).Value)))
    tempval = tempval * cell.Offset(0, 7).Value
    tempval = tempval / (cell.Offset(0, 5).Value / 1000)
    cell.Offset(0, 12).Value = tempval
    
    End If
    
         
    Next

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    19,827

    Re: [RESOLVED] Runtime Error 6 Overflow

    take out the cell.select, as it is not required and slows down the process
    change to
    vb Code:
    1. if isempty(cell) = false then
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.