mysticmario
Active Member
- Joined
- Nov 10, 2021
- Messages
- 323
- Office Version
- 365
- Platform
- 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:
Maybe I am mising something?
Please help if possible.
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
Please help if possible.