jack3427dsg546
New Member
- Joined
- Aug 17, 2022
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
I based my code off of this but I can't get my code to work. The MsgBox pops up at the end but no rows are actually deleted.
Column A of Report is the Invoice Number (alphanumeric). Column C of Invoices are the invoice numbers we already have in the system. Therefore, I want to delete the rows in Report that where Report.ColumnA matches Invoices.ColumnC. Any help would be appreciated.
Column A of Report is the Invoice Number (alphanumeric). Column C of Invoices are the invoice numbers we already have in the system. Therefore, I want to delete the rows in Report that where Report.ColumnA matches Invoices.ColumnC. Any help would be appreciated.
VBA Code:
Sub t()
Dim source As Worksheet, dest As Worksheet, i As Long, fn As Range, flg As Boolean
Set source = Workbooks("Invoices.xls").Sheets(1)
Set dest = Workbooks("Report.xlsx").Sheets(1)
For i = dest.Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
Set fn = source.Columns("C").Find(dest.Cells(i, 1).Value)
If Not fn Is Nothing Then
Rows(i).Delete
flg = True
End If
Next
If flg = True Then MsgBox "Itens deleted from Dest", vbInformation, "ITEMS DELETED"
End Sub