Need some more help on a VBA that was previously written with the help of forums members here.
I have an inventory workbook with multiple tabs. Currently I am working on an upgrade to the macro that records payments received onto the invoice tab.
Basically, the macro looks at the payment info and compares it to the invoices and looks for a match. If it finds one, it pastes the specifics from that payment onto the invoice tab. And, if it finds a duplicate (double payment), it will add it as an extra line on the invoice tab. Simple, right?
Here is the code:
I have noted what I would like to do. Once the payment info has been processed, I would like the macro to add the current date to column 7. Currently I am manually entering the date the payment was processed in this field and if the Macro see something in this field it skips the row and goes onto the next.
Any easy way to make this change?
Thanks, all!
-Bob
I have an inventory workbook with multiple tabs. Currently I am working on an upgrade to the macro that records payments received onto the invoice tab.
Basically, the macro looks at the payment info and compares it to the invoices and looks for a match. If it finds one, it pastes the specifics from that payment onto the invoice tab. And, if it finds a duplicate (double payment), it will add it as an extra line on the invoice tab. Simple, right?
Here is the code:
HTML:
Sub Payments_Received()
'Payments Received'
Dim ws3 As Worksheet, ws2 As Worksheet
Dim arr3 As Variant, arr4() As Variant
Dim lastRow As Long, i As Long, j As Long, AddRow As Long
Dim tf As Boolean
Application.ScreenUpdating = False
Set ws3 = Sheets("Payments Received")
Set ws2 = Sheets("Invoice Tracking")
lastRow = ws2.Cells(Rows.Count, 1).End(xlUp).Row
AddRow = lastRow
arr3 = ws3.Range(ws3.Cells(12, 1), ws3.Cells(42, 7)).Value
arr4 = ws2.Range(ws2.Cells(2, 1), ws2.Cells(lastRow, 9)).Value
For i = LBound(arr3) To UBound(arr3)
tf = False
For j = LBound(arr4, 1) To UBound(arr4, 1)
If (arr3(i, 1) = arr4(j, 1)) And (arr3(i, 2) = arr4(j, 2)) And arr4(j, 7) = "" And (arr3(i, 7)) = "" Then
arr4(j, 7) = arr3(i, 3)
arr4(j, 8) = arr3(i, 4)
arr4(j, 9) = arr3(i, 5)
'if this is all pasted, add the current date to arr3(i, 7)
tf = True
End If
Next j
If tf = False And (arr3(i, 7)) = "" Then
AddRow = AddRow + 1
ws2.Cells(AddRow, 1) = arr3(i, 1)
ws2.Cells(AddRow, 2) = arr3(i, 2)
ws2.Cells(AddRow, 7) = arr3(i, 3)
ws2.Cells(AddRow, 8) = arr3(i, 4)
ws2.Cells(AddRow, 9) = arr3(i, 5)
End If
'if this is all pasted, add the current date to arr3(i, 7)
Next i
ws2.Range(ws2.Cells(2, 1), ws2.Cells(lastRow, 9)).Value = arr4
I have noted what I would like to do. Once the payment info has been processed, I would like the macro to add the current date to column 7. Currently I am manually entering the date the payment was processed in this field and if the Macro see something in this field it skips the row and goes onto the next.
Any easy way to make this change?
Thanks, all!
-Bob
Last edited: