Overflow error

mysticmario

Active Member
Joined
Nov 10, 2021
Messages
323
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have an issue with a code thaht collects and sorts data on the sheet I am using Long instead of Int to describe rows so i dont know how to get rid off it. debugger marks this line: arrPanel = .Range("B1:E" & lrPanel) as the problem, but here is the entire sub code code:

VBA Code:
    Dim iRow As Long, lrWs As Long, ws As Worksheet
    Dim lrPanel As Long, lrPanelDate As Long
    Dim wsPanel As Worksheet
  
    Application.ScreenUpdating = False
  
    Set wsPanel = Worksheets("PANEL PODLICZEŃ")
    ' Append data
    For Each ws In Worksheets
        If InStr(1, ws.Name, "Faktury", vbTextCompare) Then
            iRow = wsPanel.Range("D" & Rows.count).End(3).Row + 1
            lrWs = ws.Range("D" & Rows.count).End(3).Row
            ws.Range("C6:C" & lrWs).Resize(, 3).Copy
            wsPanel.Range("C" & iRow).PasteSpecial xlPasteValues
            lrPanel = wsPanel.Cells(Rows.count, "D").End(xlUp).Row
            wsPanel.Range(wsPanel.Cells(iRow, "B"), wsPanel.Cells(lrPanel, "B")).Value = ws.Range("C3").Value
        End If
    Next
  
    ' Sort Data on Date field
    wsPanel.sort.SortFields.Clear
    wsPanel.sort.SortFields.Add2 Key:=Range( _
        "D1:D" & lrPanel), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
        xlSortNormal
    With wsPanel.sort
        .SetRange Range("B:E")              ' XXX Extended sort range
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
  
    ' Remove non-data rows
    Dim arrPanel As Variant, arrOut() As Variant
    Dim iOut As Long, i As Long, j As Long

    With wsPanel
        arrPanel = .Range("B1:E" & lrPanel)
        .Range(.Cells(1, "B"), .Cells(lrPanel, "E")).ClearContents
    End With
  
    ReDim arrOut(1 To UBound(arrPanel, 1), 1 To UBound(arrPanel, 2))
  
    For i = 1 To UBound(arrPanel, 1)
        If IsDate(arrPanel(i, 3)) And arrPanel(i, 3) <> 0 And arrPanel(i, 4) <> "" Then
            iOut = iOut + 1
            For j = 1 To UBound(arrPanel, 2)
                arrOut(iOut, j) = arrPanel(i, j)
            Next j
        End If
    Next i
      
    wsPanel.Range("B1").Resize(iOut, UBound(arrPanel, 2)).Value = arrOut
  
    Application.ScreenUpdating = True
Maybe I am mising something?
Please help if possible.
 
Previously the data all these sheets and ranges was imported to the sheet but it was a mess it had invalid dates, or had the date cell be completely empty or even there was som3thins completely different than date as a value. This time around - after the changes when i get to an error no data is being shown on the sheet, so there is no data to check through conditions.
Before i came here for help and before we switched the arrPanel to value2 i had the overflow error but the data was being imported, just the "cleaning" part wasnt working.
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
iOut only gets incremented if this line is true:

Code:
If IsDate(arrPanel(i, 3)) And arrPanel(i, 3) <> 0 And arrPanel(i, 4) <> "" Then

if iOut is 0, then no lines in the input data met those three criteria. Your code should really test if iOut is 0 before trying to output an empty array to a range 0 rows high (which is what causes the 1004 error).
 
Upvote 0
There are no lines in the inpuit data because the enitre arrPanel range is empty.
Here's what I get when i just end the sub after i get an overlow error using .value
 

Attachments

  • data.png
    data.png
    187.4 KB · Views: 7
  • data2.png
    data2.png
    218.4 KB · Views: 7
Upvote 0
and this is what i end up with afetr i change .value into .value2 - empty data range
 

Attachments

  • after-changes.png
    after-changes.png
    182 KB · Views: 5
Upvote 0
We already sorted out the overflow error, did we not? If arrPanel is empty, there is no point in processing it at all.
 
Upvote 0
a
We already sorted out the overflow error, did we not? If arrPanel is empty, there is no point in processing it at all.
After sorting out overflow error, data is not being pulled at all. arrPanel will never be empty in my case because this is a list of invoices sorted between different project sheets. It's just being pulled togetehr witha lot of junk data
 
Upvote 0
Ah, OK. The issue is that Value2 will pull dates through as serial numbers, and IsDate will not return True for those.

What kind of non-date data are you expecting in column C?
 
Upvote 0
this is what a proper data after cleaning and sortign looks like:
1693479631555.png


but the data is being pulled from a sheet that looks like this:
1693479761025.png

as you can see data pulled into column C is a invoice number but the "source sheet" in the same column as invoice number (C), also has text such as "Last period Net" or other, which is being pulled along side the invoice number, to add to that also multiple instances of "bad" data (empty cells, wrong dates etc) is being pulled while the code goes through the entire workbook.
some examplr of bad data can be seen here:
1693479970954.png
 

Attachments

  • 1693479716364.png
    1693479716364.png
    104.9 KB · Views: 6
Upvote 0
I suspect the issue is being caused by the total calculations at the bottom of the source sheets and column D on the panel sheet having a date format applied. Try amending the first section of code to:

VBA Code:
    Dim iRow As Long, lrWs As Long, ws As Worksheet
    Dim lrPanel As Long, lrPanelDate As Long
    Dim wsPanel As Worksheet
  
    Application.ScreenUpdating = False
  
    Set wsPanel = Worksheets("PANEL PODLICZEN")
    wsPanel.Range("D:D").ClearFormats
    ' Append data
    For Each ws In Worksheets
        If InStr(1, ws.Name, "Faktury", vbTextCompare) Then
            iRow = wsPanel.Range("D" & Rows.Count).End(3).Row + 1
            lrWs = ws.Range("D" & Rows.Count).End(3).Row
            ws.Range("C6:C" & lrWs).Resize(, 3).Copy
            wsPanel.Range("C" & iRow).PasteSpecial xlPasteValuesAndNumberFormats
            lrPanel = wsPanel.Cells(Rows.Count, "D").End(xlUp).Row
            wsPanel.Range(wsPanel.Cells(iRow, "B"), wsPanel.Cells(lrPanel, "B")).Value = ws.Range("C3").Value
        End If
    Next

which will clear the date formats and paste the source number formatting. Then go back to using Value instead of Value2.
 
Upvote 0
Solution

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

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