Consulting

Results 1 to 4 of 4

Thread: Solved: Overflow Error in Code

  1. #1
    VBAX Regular
    Joined
    Jul 2013
    Posts
    10
    Location

    Solved: Overflow Error in Code

    The function executed for me yesterday and this morning I am getting an overflow error. Any idea why?

    [vba]Sub three_point()
    Set c11 = Range("A1")
    Dim i As Integer
    i = 2
    p = 2

    Do Until Range("A2") = ""
    If Abs(Cells(i, 1).Value - Cells(i + 1, 1).Value) < Abs(Cells(i + 1, 1).Value - Cells(i + 2, 1).Value) Then
    Cells(p, 8).Value = Abs(Cells(i, 1).Value - Cells(i + 1, 1).Value)
    Cells(p, 9).Value = (Cells(i, 1).Value + Cells(i + 1, 1).Value) / 2
    Cells(i + 1, 1).Delete shift:=xlUp
    Cells(i, 1).Delete shift:=xlUp
    i = 2
    p = p + 1
    Else
    i = i + 1
    End If
    Loop
    End Sub[/vba]

    thanks for the help.

  2. #2
    VBAX Mentor
    Joined
    Jul 2012
    Posts
    398
    Location
    need a sample file for testing

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    How was the issue solved?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  4. #4
    VBAX Regular
    Joined
    Jul 2013
    Posts
    10
    Location
    Quote Originally Posted by Aussiebear
    How was the issue solved?

    I was accidentaly using A2 instead of A3 in the Do Until loop and it was an infinite loop.

    [VBA]
    Sub three_point()
    Set c11 = Range("A1")
    Dim i As Integer
    i = 2
    p = 2

    Do Until Range("A3") = ""
    If Abs(Cells(i, 1).Value - Cells(i + 1, 1).Value) < Abs(Cells(i + 1, 1).Value - Cells(i + 2, 1).Value) Then
    Cells(p, 8).Value = Abs(Cells(i, 1).Value - Cells(i + 1, 1).Value)
    Cells(p, 9).Value = (Cells(i, 1).Value + Cells(i + 1, 1).Value) / 2
    Cells(i + 1, 1).Delete shift:=xlUp
    Cells(i, 1).Delete shift:=xlUp
    i = 2
    p = p + 1
    Else
    i = i + 1
    End If
    Loop
    End Sub
    [/VBA]

Posting Permissions

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