+ Reply to Thread
Results 1 to 3 of 3

overflow error

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    overflow error

    Hello,

    The following code works if there are 4 values in B2:B, however if there are only 3 and one of the values is zero or blank I get an overflow error. Can a line of code be put in that if the value of B2:B = 0 Then it is ignored or not calculated? I have attached the spreadsheet as well.Thanks.

    Private Sub CommandButton1_Click()
    Dim lRow As Long: lRow = Cells(Rows.Count, 1).End(xlUp).Row
    Dim myArray()
    Dim x As Long
    
    
    
    
    myArray = Range("B2:B" & lRow)
    
    
    For x = 1 To UBound(myArray)
    If myArray(x, 1) > 100 Then
    Cells(x + 1, "C") = myArray(x, 1) / 10
    Cells(x + 1, "D") = (myArray(x, 1) / 2) / Cells(x + 1, "C")
    Cells(x + 1, "E") = (myArray(x, 1) / 2) - Cells(x + 1, "D")
    
    
    Else
    Cells(x + 1, "C") = myArray(x, 1) / 10
    Cells(x + 1, "D") = (myArray(x, 1) / Cells(x + 1, "C"))
    Cells(x + 1, "E") = myArray(x, 1) - Cells(x + 1, "D")
    End If
    
    
    Next
    End Sub

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: overflow error

    Hi cmccabe,
    try
    Private Sub CommandButton1_Click()
    Dim lRow As Long, myArray, x As Long
    lRow = Cells(Rows.Count, 2).End(xlUp).Row
    If lRow = 1 Then Exit Sub
    myArray = Range("B1:B" & lRow).Value
    For x = 2 To UBound(myArray)
        If myArray(x, 1) > 100 Then
            Cells(x, "C") = myArray(x, 1) / 10
            If Cells(x, "C") = 0 Then Cells(x, "D") = 0 Else Cells(x, "D") = (myArray(x, 1) / 2) / Cells(x, "C")
            Cells(x, "E") = (myArray(x, 1) / 2) - Cells(x, "D")
        Else
            Cells(x, "C") = myArray(x, 1) / 10
            If Cells(x, "C") = 0 Then Cells(x, "D") = 0 Else Cells(x, "D") = myArray(x, 1) / Cells(x, "C")
            Cells(x, "E") = myArray(x, 1) - Cells(x, "D")
        End If
    Next
    End Sub
    Last edited by nilem; 04-09-2014 at 12:56 PM. Reason: edited code

  3. #3
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: overflow error

    Thank you very much

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Explanation of the Run-time error '6': Overflow Error
    By mgphill in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-25-2012, 10:46 AM
  2. Want to do a while-loop but get error message: run error '6' overflow
    By danzi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-07-2011, 01:48 PM
  3. Overflow error
    By share knowledge in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-02-2010, 02:07 AM
  4. Overflow Error
    By transparencia in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-25-2010, 02:21 PM
  5. Overflow Error
    By narrowgate88 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-10-2010, 02:08 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1