+ Reply to Thread
Results 1 to 13 of 13

Run time error 6 = over flow

  1. #1
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Run time error 6 = over flow

    Hello experts
    The code is working fine in sample data. But when I ran the code in the original data with more than 1,40,000 rows, the code is displaying the above error message. Please tell me how to over come that message and get the same result.
    Thank you in advance.
    Attached Files Attached Files
    Last edited by RAJESH SHAH; 03-30-2023 at 03:33 AM. Reason: #Solved by John Topley

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: Run time error 6 = over flow

    Try

    Please Login or Register  to view this content.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Run time error 6 = over flow

    Wow!! How much difference it makes with just one change. It is working now. Thanks once again John Topley.

  4. #4
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Run time error 6 = over flow

    Corrected the replacement of and to & code too.

  5. #5
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: Run time error 6 = over flow

    As a general rule you can "Dim" all integer variable as "Long" to avoid this problem; but "mea culpa" for the mistake!

  6. #6
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Run time error 6 = over flow

    No problem. I could not find the latin word for No problem 😜

  7. #7
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Run time error 6 = over flow

    To help code faster, working with big data.
    Use this coe:
    PHP Code: 
    Option Explicit
    Sub CreateS
    ()
    Application.StatusBar "Create Sales Headings with Data..."

    'delete old Sales sheet
    If Evaluate("=ISREF('
    Sales'!A1)") Then Sheets("Sales").Delete

    '
    dupplicate sheet "consolidated" intead of create new sheet
    Application
    .DisplayAlerts False
    Sheets
    ("consolidated").Copy after:=Sheets(Sheets.Count)
    ActiveSheet.Name "Sales"
    Application.DisplayAlerts True

    'with new Sales sheet, delete specific columns
    Range("E5:G5,J5,L5,Q5,S5,U5,W5").EntireColumn.Delete

    '
    insert 1 more column P for "rate %"
    Columns("P").Insert

    'create headers and format in row 1
    Rows("2:5").Delete
    With Range("A1:U1")
        .Value = Array("Revenue Group", "Shipped Location", "Order no", "GSTIN/UIN", "No.", "Date", "Quantity", _
                "Value", "Goods/Services", "HSN/SAC", "Taxable Value", "IGST", "CGST", "SGST", "CESS", "Rate %", "Location of Recipient", _
                "Supply Type", "Code", "State Code", "Nature of supply")
        .Font.Bold = True
        .EntireColumn.AutoFit
    End With

    '
    main code
    Dim lr
    &, i&, j&, rnggstfary1ary2
    lr 
    Cells(Rows.Count"L").End(xlUp).Row
    'copy data into array "rng" and "gst", to avoid working directly on sheet, to help code faster
    rng = Range("K2:U" & lr).Value: gst = Range("D2:D" & lr).Value
    ary1 = Array("URP", "Export", "Cancelled"): ary2 = Array("B2C", "Export", "Cancelled")
    For i = 1 To UBound(rng)
        On Error Resume Next
        rng(i, 6) = Round((rng(i, 2) + rng(i, 3) + rng(i, 4)) / rng(i, 1), 2) * 100
        On Error GoTo 0
        With Sheets("State Code")
            Set f = .Range("B2:B38").Find(Trim(rng(i, 7))) ' 
    looking for Location in column B
            
    If Not f Is Nothing Then ' if found then
                rng(i, 9) = f.Offset(, 1).Value ' 
    get corresponding value in column C
                rng
    (i10) = f.Offset(, 2).Value ' get corresponding value in column D
            Else ' 
    if not found then
                rng
    (i9) = "OT"
                
    rng(i10) = 97
            End 
    If
            
    rng(i11) = "B2B" ' set defaul value is B2B
            For j = 0 To UBound(ary1)
                If gst(i, 1) = ary1(j) Then rng(i, 11) = ary2(j) ' 
    if column D matchs ary1 the returns corresponding item in ary2
            Next
        End With
    Next
    'paste array back to sheet
    Range("K2:U" & lr).Value = rng
    End Sub 
    Attached Files Attached Files
    Quang PT

  8. #8
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: Run time error 6 = over flow

    "Nil desparandum" !

  9. #9
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Run time error 6 = over flow

    No need to despair.

  10. #10
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Run time error 6 = over flow

    Thanks Bebo. The code actually took less than 1]2 the time. It will take time for me to understand the code. Till then I will use it once I am able to understand the whole code. Anyways thank you.🙏

  11. #11
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: Run time error 6 = over flow

    Learn from Bebo's approach as (from your posting history) much of your processing is very similar to this requirement. And note, (memory-based) array processing is very fast ( - the latter part of Bebo's macro).

    Another variation

    Please Login or Register  to view this content.

    Data from "Consolidate" is read into array "a" and then copied to array "b" which represents the "Sales" data.

    Arrays "a" and "b" could be better named which helps to document the macro: I am just being lazy!!!
    Last edited by JohnTopley; 03-30-2023 at 07:03 AM.

  12. #12
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Run time error 6 = over flow

    John Topley. You are great, man. Now you have understood how important the comments are for a new bee like me. If you check my earlier posts you will see that I have been requesting everyone to write comments for better understanding. Now that you have understood, hopefully others may follow. Thank you for the comments. Will go through the code in my free time and understand this new way of coding to make the code to run faster. I have understood one thing till now that the code takes more time when there are multiple formulas involved.
    Right now I have received requests to make some changes in the code as per their requirement. Will post it as a new thread if I am not able to do the editing. Till then Happy solving....

  13. #13
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Run time error 6 = over flow

    WoW!! This is amazing. The code displays the result very fast. Earlier it was 200 seconds then 70 seconds with bebo's code and now 20 seconds. Thanks to bebo for this idea...

+ 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. Run-time error '6': Over flow
    By jamest765 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-08-2020, 03:28 PM
  2. Physics Question. Electron Flow and Current flow
    By JimmyWilliams in forum Excel General
    Replies: 4
    Last Post: 11-08-2017, 12:01 AM
  3. [SOLVED] Over Flow Error when copying columns
    By jquintana83 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-05-2014, 12:11 PM
  4. [SOLVED] Lookup Flow IN / OUT & Time & Date Query Help PLease
    By thorrrr in forum Excel General
    Replies: 9
    Last Post: 07-07-2014, 08:05 AM
  5. over flow run time error 6
    By AB33 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-22-2012, 01:39 PM
  6. tracking flow / lead time need help
    By itwrx in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-27-2011, 12:50 PM
  7. Spread Cash Flow over Different Time Periods
    By mhpotter81 in forum Excel General
    Replies: 3
    Last Post: 11-23-2010, 03:43 PM

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