Currently my code looks for "Invoice" in column A and copies the row to a new workbook. Works well. However, i need to capture the Reference name and number for that invoice number. Any help would be welcomed
Currently it looks like so:
<tbody>
</tbody>
However i need it to capture
<tbody>
</tbody>
My code
Sample data
<colgroup><col style="width:43pt" span="2" width="57"> <col style="width:128pt" width="170"> <col style="width:8pt" width="11"> <col style="width:39pt" width="52"> <col style="width:50pt" span="2" width="66"> <col style="width:2pt" width="2"> <col style="width:50pt" span="2" width="66"> <col style="width:9pt" width="12"> <col style="width:41pt" width="55"> <col style="width:6pt" width="8"> <col style="width:5pt" width="7"> <col style="width:21pt" width="28"> <col style="width:2pt" width="3"> <col style="width:13pt" width="17"> <col style="width:1pt" width="1"> <col style="width:2pt" width="2"> </colgroup><tbody>
</tbody>
Currently it looks like so:
Invoice | 43041 | 2298 | 115992.11 | 0 | 0 | 115992.11 | 0 | 0 |
<tbody>
</tbody>
However i need it to capture
Invoice | 43041 | 2298 | 115992.11 | 0 | 0 | 115992.11 | 0 | 0 | V00859 | Automotive & Engineering P/L |
<tbody>
</tbody>
My code
Code:
Sub copyBurnDownItem()
Dim srcWorkbook As Workbook
Dim desWorkbook As Workbook
Dim objWorksheet As Worksheet
Dim objNewSheet As Worksheet
Dim rngBurnDown As Range
Dim rngCell As Range
Dim strPasteToSheet As String
'Used for the new worksheet we are pasting into
Dim rngNextAvailbleRow As Range
Set desWorkbook = Workbooks.Open("C:\test\master_audit.xlsm")
Set srcWorkbook = Workbooks.Open("C:\test\current.xlsx")
Set objWorksheet = srcWorkbook.Worksheets("Sheet1")
'Clear data
desWorkbook.Sheets("import").Cells.Clear
srcWorkbook.Activate
'Dynamically define the range to the last cell.
'This doesn't include and error handling e.g. null cells
'If we are not starting in A1, then change as appropriate
Set rngBurnDown = objWorksheet.Range("A1:A" & objWorksheet.Cells(Rows.Count, "A").End(xlUp).Row)
'Now loop through all the cells in the range
For Each rngCell In rngBurnDown.Cells
srcWorkbook.Activate
objWorksheet.Select
If rngCell.Value = "Invoice" Then
'select the entire row
rngCell.EntireRow.Select
'copy the selection
Selection.Copy
'Now identify and select the new sheet to paste into
Set objNewSheet = desWorkbook.Worksheets("import")
desWorkbook.Activate
objNewSheet.Select
Set rngNextAvailbleRow = objNewSheet.Range("A1:A" & objNewSheet.Cells(Rows.Count, "A").End(xlUp).Row)
Range("A" & rngNextAvailbleRow.Rows.Count + 1).Select
'ActiveSheet.PasteSpecial Operation:=xlPasteValues
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End If
Next rngCell
objWorksheet.Select
objWorksheet.Cells(1, 1).Select
'Can do some basic error handing here
srcWorkbook.Activate
Application.DisplayAlerts = False
srcWorkbook.Close
Application.DisplayAlerts = True
desWorkbook.Activate
'kill all objects
If IsObject(objWorksheet) Then Set objWorksheet = Nothing
If IsObject(rngBurnDown) Then Set rngBurnDown = Nothing
If IsObject(rngCell) Then Set rngCell = Nothing
If IsObject(objNewSheet) Then Set objNewSheet = Nothing
If IsObject(rngNextAvailbleRow) Then Set rngNextAvailbleRow = Nothing
End Sub
Sample data
Type | Date | Reference | Currency Code | Original Amount | Previously Applied | Withholding Tax Deducted | This Payment | This Payment Discount | Balance Due |
Invoice | 2/11/2017 | 2298 | 115,992.11 | 0.00 | 0.00 | 115,992.11 | 0.00 | 0.00 | |
V00859 | Automotive & Engineering P/L | ||||||||
115,992.11 | |||||||||
Invoice | 1/09/2017 | DEBTOR 25301 JULY 2017 | 772.00 | 0.00 | 0.00 | 772.00 | 0.00 | 0.00 | |
Invoice | 20/10/2017 | PJ000173 | 328.05 | 0.00 | 0.00 | 328.05 | 0.00 | 0.00 | |
Invoice | 3/11/2017 | PJ000179 | 275.58 | 0.00 | 0.00 | 275.58 | 0.00 | 0.00 | |
V00054 | Jumble Jim |
<colgroup><col style="width:43pt" span="2" width="57"> <col style="width:128pt" width="170"> <col style="width:8pt" width="11"> <col style="width:39pt" width="52"> <col style="width:50pt" span="2" width="66"> <col style="width:2pt" width="2"> <col style="width:50pt" span="2" width="66"> <col style="width:9pt" width="12"> <col style="width:41pt" width="55"> <col style="width:6pt" width="8"> <col style="width:5pt" width="7"> <col style="width:21pt" width="28"> <col style="width:2pt" width="3"> <col style="width:13pt" width="17"> <col style="width:1pt" width="1"> <col style="width:2pt" width="2"> </colgroup><tbody>
</tbody>