Hi all/Snakehips,
I have an error in the line below shown in red, "Run time error 5: Invalid procedure call or argument". It runs only the first loop (or first "cell") and then the error appears on its way to the next "cell".
Can someone please help? It'll be gratefully appreciated.
Sub Invoices()
Dim extract As Worksheet
Dim GoodData As Worksheet
Dim cell As Range
Dim i As Long
Dim firstAddress As Variant
Dim total As Range
Dim FoundCell As Range
Dim FirstRow As Long
Dim BlockStart As Long
BlockStart = 15
Set extract = Sheets("Extracts 0011")
Set GoodData = Sheets("GoodData")
Set cell = Range("C:C").Find("Vendor*", LookIn:=xlValues)
Set FoundCell = Range("E:E").Find(What:="~* Total", LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False) '"After" option removed
If Not cell Is Nothing Then
firstAddress = cell.Address
Do
If Not FoundCell Is Nothing Then
FirstRow = FoundCell.Row
Else
MsgBox "No data blocks found"
End If
Do Until FoundCell Is Nothing
Dim Blockrows As Long
Blockrows = (FoundCell.Row - BlockStart) - 1
For i = 1 To Blockrows Step 2
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(1, 0).Value = cell.End(xlDown).Offset(0, 2).End(xlDown).Value 'payment/exception
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 5).Value = cell.Offset(1, 0).Value 'supplier name
'address details
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 18).Value = cell.Offset(2, 0).Value
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 19).Value = cell.Offset(3, 0).Value
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 20).Value = cell.Offset(4, 0).Value
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 21).Value = cell.Offset(5, 0).Value
'Other details
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 25).Value = cell.End(xlDown).Offset(0, 2).End(xlDown).Offset(i, 0).Value 'CoCode
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 19).Value = cell.End(xlDown).Offset(0, 2).End(xlDown).Offset(i + 1, 0).Value 'ISR Number
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 1).Value = cell.End(xlDown).Offset(0, 2).End(xlDown).Offset(i, 4).Value 'Vendor No
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 20).Value = cell.End(xlDown).Offset(0, 2).End(xlDown).Offset(i + 1, 8).Value 'ISR Reference Number
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 2).Value = cell.End(xlDown).Offset(0, 2).End(xlDown).Offset(i, 12).Value 'Doc No
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 4).Value = cell.End(xlDown).Offset(0, 2).End(xlDown).Offset(i, 18).Value 'payment type
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 3).Value = cell.End(xlDown).Offset(0, 2).End(xlDown).Offset(i, 17).Value 'Supplier Invoice No
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 13).Value = cell.End(xlDown).Offset(0, 2).End(xlDown).Offset(i, 10).Value 'Park code
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 7).Value = cell.End(xlDown).Offset(0, 2).End(xlDown).Offset(i, 30).Value 'posting date
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 8).Value = cell.End(xlDown).Offset(0, 2).End(xlDown).Offset(i, 24).Value 'date 2
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 10).Value = cell.End(xlDown).Offset(0, 2).End(xlDown).Offset(i, 38).Value 'type 1
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 6).Value = cell.End(xlDown).Offset(0, 2).End(xlDown).Offset(i, 39).Value 'value
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 12).Value = cell.End(xlDown).Offset(0, 2).End(xlDown).Offset(i, 46).Value 'currency
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 11).Value = cell.End(xlDown).Offset(0, 2).End(xlDown).Offset(i, 48).Value 'Type 2
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 9).Value = cell.End(xlDown).Offset(0, 2).End(xlDown).Offset(i, 33).Value 'Net due date
'Bank details
'use transpose method for bank and adress details
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 14).Value = cell.Offset(1, 43).Value
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 15).Value = cell.Offset(2, 43).Value
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 16).Value = cell.Offset(3, 43).Value
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 17).Value = cell.Offset(4, 43).Value
GoodData.Cells(GoodData.Rows.Count, 1).End(xlUp).Offset(0, 18).Value = cell.Offset(5, 43).Value
Next
Set cell = Range("C:C").FindNext(cell)
Set FoundCell = Range("E:E").FindNext(after:=FoundCell)
BlockStart = FoundCell.Row + 15
If FoundCell.Row = FirstRow Then Exit Do
Loop
Loop While Not cell Is Nothing And cell.Address <> firstAddress
End If
MsgBox "Report created"
End Sub