VBA Run time error - 6 - Overflow

Guinaba

Board Regular
Joined
Sep 19, 2018
Messages
233
Office Version
  1. 2016
Platform
  1. Windows
Hi guys,

I am running the code below to copy data from one sheet to another, every day. However, the code start failing with overflow error. The file I am copying the data to has 2Mb the data goes up to row 39700, so I dont think is data issue yet. The code is failing when it finds the last row to copy the data. It looks like I don't have enough memory to run the code? Should I use array to avoid this issue?

Error in the code:

1686695745588.png




VBA Code:
Sub PlannedOrdersHistory()

    Application.ScreenUpdating = False

    Dim CurrDate As Date
    CurrDate = Date
    Dim CurrFileName As String
    CurrFileName = Format(CurrDate, "yyyymmdd") & "_ED_Fcst_VS_Planned_Orders_V10" & ".XLSM"
    Dim Wb1 As Workbook: Set Wb1 = Workbooks(CurrFileName)
    Dim Wb2 As Workbook: Set Wb2 = Workbooks.Open("C:\Users\gnassifb\OneDrive - Lion Pty Ltd\Documents\ED\ED Planned Orders\ED_Planned_Orders_History_1.xlsx")
    Dim LRow As Integer
    Dim SearchString As String
    Dim SearchRange As Range
    LastDate = WorksheetFunction.Max(Wb2.Worksheets("ED_Planned_Orders_History_1").Range("A:A"))

    With Wb2.Worksheets("ED_Planned_Orders_History_1")
      'Find the last non-blank cell in column A(1)
       LRow = .Cells(Rows.Count, 1).End(xlUp).Row
    End With

    'Check if the data is already copied
    If LastDate <> Date Then
       Wb1.Worksheets("EDPlannedOrders").ListObjects("tPlannedOrdersWeekly").DataBodyRange.Copy
       Wb2.Worksheets("ED_Planned_Orders_History_1").Range("A" & LRow + 1).PasteSpecial xlPasteValuesAndNumberFormats
    Else
        MsgBox "Data is already copied", vbExclamation: Exit Sub

    End If

    'Wb2.Close SaveChanges:=True
    Application.CutCopyMode = False

 End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
"Dim LRow As Integer"
The max value for an Integer is = 32767

Declare LRow as long
VBA Code:
Dim LRow As Long
 
Upvote 1
Solution

Forum statistics

Threads
1,223,162
Messages
6,170,431
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top