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.
Last edited by RAJESH SHAH; 03-30-2023 at 03:33 AM.
Reason: #Solved by John Topley
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&, rng, gst, f, ary1, ary2 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(i, 10) = f.Offset(, 2).Value ' get corresponding value in column D Else ' if not found then rng(i, 9) = "OT" rng(i, 10) = 97 End If rng(i, 11) = "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
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.🙏
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).
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....
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...
Bookmarks