Hello,
I have a problem where I want to be able to search a particular column and then copy that entire row to a new workbook based on the value found in the particular column.
I have the following worksheet called '2016':-
[TABLE="width: 1709"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]H[/TD]
[TD]I[/TD]
[TD]J[/TD]
[TD]K[/TD]
[TD]L[/TD]
[TD]M[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]DATE[/TD]
[TD]NAME[/TD]
[TD]DATE PAID[/TD]
[TD]INV NO[/TD]
[TD]NET[/TD]
[TD]VAT[/TD]
[TD]TOTAL[/TD]
[TD]Daily net[/TD]
[TD]Gross Total Outstanding[/TD]
[TD][/TD]
[TD]Net LC[/TD]
[TD]Net TB[/TD]
[TD]Monthly Totals[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]06/10/2016[/TD]
[TD]Customer 1[/TD]
[TD]06/10/2016[/TD]
[TD]38216[/TD]
[TD]130.68[/TD]
[TD]26.14[/TD]
[TD]156.82[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]06/10/2016[/TD]
[TD]TB - TB101 Customer 2[/TD]
[TD]deposit paid[/TD]
[TD]38217[/TD]
[TD]11,990.00[/TD]
[TD]2,398.00[/TD]
[TD]14,388.00[/TD]
[TD][/TD]
[TD="align: right"]7194.00[/TD]
[TD]Balance Remain[/TD]
[TD][/TD]
[TD="align: right"]11990.00[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]06/10/2016[/TD]
[TD]TB - TB102 Customer 3[/TD]
[TD]deposit paid[/TD]
[TD]38218[/TD]
[TD]1,170.00[/TD]
[TD]234.00[/TD]
[TD]1,404.00[/TD]
[TD][/TD]
[TD="align: right"]702.00[/TD]
[TD]Balance Remain[/TD]
[TD][/TD]
[TD="align: right"]1170.00[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]06/10/2016[/TD]
[TD]MM - MM101 Customer 4[/TD]
[TD]deposit paid[/TD]
[TD]38219[/TD]
[TD]4,383.33[/TD]
[TD]876.67[/TD]
[TD]5,260.00[/TD]
[TD][/TD]
[TD="align: right"]2630.00[/TD]
[TD]Balance Remain[/TD]
[TD="align: right"]4383.33[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]06/10/2016[/TD]
[TD]Customer 5[/TD]
[TD][/TD]
[TD]38220[/TD]
[TD]117.00[/TD]
[TD]23.40[/TD]
[TD]140.40[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]06/10/2016[/TD]
[TD]TB - TB103 Customer 6[/TD]
[TD]deposit paid[/TD]
[TD]38221[/TD]
[TD]258.33[/TD]
[TD]51.67[/TD]
[TD]310.00[/TD]
[TD="align: right"]18,049.34[/TD]
[TD="align: right"]155.00[/TD]
[TD]Balance Remain[/TD]
[TD][/TD]
[TD="align: right"]258.33[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]07/10/2016[/TD]
[TD]Customer 7[/TD]
[TD][/TD]
[TD]38222[/TD]
[TD]3.92[/TD]
[TD]0.78[/TD]
[TD]4.70[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]07/10/2016[/TD]
[TD]Customer 8[/TD]
[TD][/TD]
[TD]38223[/TD]
[TD]127.37[/TD]
[TD]25.47[/TD]
[TD]152.84[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]07/10/2016[/TD]
[TD]Customer 9[/TD]
[TD]07/10/2016[/TD]
[TD]38224[/TD]
[TD]231.05[/TD]
[TD]46.21[/TD]
[TD]277.26[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD]07/10/2016[/TD]
[TD]Customer 10[/TD]
[TD][/TD]
[TD]38225[/TD]
[TD]928.05[/TD]
[TD]185.61[/TD]
[TD]1,113.66[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD]07/10/2016[/TD]
[TD]Customer 11[/TD]
[TD][/TD]
[TD]38226[/TD]
[TD]238.83[/TD]
[TD]47.77[/TD]
[TD]286.60[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]13[/TD]
[TD]07/10/2016[/TD]
[TD]Customer 12[/TD]
[TD][/TD]
[TD]38227[/TD]
[TD]92.73[/TD]
[TD]18.55[/TD]
[TD]111.28[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
I would like VBA code to be able to search column C for "deposit paid", if this parameter is met, I would like to copy the entire row to a new workbook, including formatting.
I am currently using the following code, however it only copies the workbook headers and first row but without using the 'Column C' parameters I require.
Any help anyone can provide is very much appreciated.
Many thanks,
Pad
I have a problem where I want to be able to search a particular column and then copy that entire row to a new workbook based on the value found in the particular column.
I have the following worksheet called '2016':-
[TABLE="width: 1709"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]H[/TD]
[TD]I[/TD]
[TD]J[/TD]
[TD]K[/TD]
[TD]L[/TD]
[TD]M[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]DATE[/TD]
[TD]NAME[/TD]
[TD]DATE PAID[/TD]
[TD]INV NO[/TD]
[TD]NET[/TD]
[TD]VAT[/TD]
[TD]TOTAL[/TD]
[TD]Daily net[/TD]
[TD]Gross Total Outstanding[/TD]
[TD][/TD]
[TD]Net LC[/TD]
[TD]Net TB[/TD]
[TD]Monthly Totals[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]06/10/2016[/TD]
[TD]Customer 1[/TD]
[TD]06/10/2016[/TD]
[TD]38216[/TD]
[TD]130.68[/TD]
[TD]26.14[/TD]
[TD]156.82[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]06/10/2016[/TD]
[TD]TB - TB101 Customer 2[/TD]
[TD]deposit paid[/TD]
[TD]38217[/TD]
[TD]11,990.00[/TD]
[TD]2,398.00[/TD]
[TD]14,388.00[/TD]
[TD][/TD]
[TD="align: right"]7194.00[/TD]
[TD]Balance Remain[/TD]
[TD][/TD]
[TD="align: right"]11990.00[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]06/10/2016[/TD]
[TD]TB - TB102 Customer 3[/TD]
[TD]deposit paid[/TD]
[TD]38218[/TD]
[TD]1,170.00[/TD]
[TD]234.00[/TD]
[TD]1,404.00[/TD]
[TD][/TD]
[TD="align: right"]702.00[/TD]
[TD]Balance Remain[/TD]
[TD][/TD]
[TD="align: right"]1170.00[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]06/10/2016[/TD]
[TD]MM - MM101 Customer 4[/TD]
[TD]deposit paid[/TD]
[TD]38219[/TD]
[TD]4,383.33[/TD]
[TD]876.67[/TD]
[TD]5,260.00[/TD]
[TD][/TD]
[TD="align: right"]2630.00[/TD]
[TD]Balance Remain[/TD]
[TD="align: right"]4383.33[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]06/10/2016[/TD]
[TD]Customer 5[/TD]
[TD][/TD]
[TD]38220[/TD]
[TD]117.00[/TD]
[TD]23.40[/TD]
[TD]140.40[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]06/10/2016[/TD]
[TD]TB - TB103 Customer 6[/TD]
[TD]deposit paid[/TD]
[TD]38221[/TD]
[TD]258.33[/TD]
[TD]51.67[/TD]
[TD]310.00[/TD]
[TD="align: right"]18,049.34[/TD]
[TD="align: right"]155.00[/TD]
[TD]Balance Remain[/TD]
[TD][/TD]
[TD="align: right"]258.33[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]07/10/2016[/TD]
[TD]Customer 7[/TD]
[TD][/TD]
[TD]38222[/TD]
[TD]3.92[/TD]
[TD]0.78[/TD]
[TD]4.70[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]07/10/2016[/TD]
[TD]Customer 8[/TD]
[TD][/TD]
[TD]38223[/TD]
[TD]127.37[/TD]
[TD]25.47[/TD]
[TD]152.84[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]07/10/2016[/TD]
[TD]Customer 9[/TD]
[TD]07/10/2016[/TD]
[TD]38224[/TD]
[TD]231.05[/TD]
[TD]46.21[/TD]
[TD]277.26[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD]07/10/2016[/TD]
[TD]Customer 10[/TD]
[TD][/TD]
[TD]38225[/TD]
[TD]928.05[/TD]
[TD]185.61[/TD]
[TD]1,113.66[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD]07/10/2016[/TD]
[TD]Customer 11[/TD]
[TD][/TD]
[TD]38226[/TD]
[TD]238.83[/TD]
[TD]47.77[/TD]
[TD]286.60[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]13[/TD]
[TD]07/10/2016[/TD]
[TD]Customer 12[/TD]
[TD][/TD]
[TD]38227[/TD]
[TD]92.73[/TD]
[TD]18.55[/TD]
[TD]111.28[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
I would like VBA code to be able to search column C for "deposit paid", if this parameter is met, I would like to copy the entire row to a new workbook, including formatting.
I am currently using the following code, however it only copies the workbook headers and first row but without using the 'Column C' parameters I require.
Code:
Sub GenerateList()
Dim Cell As Range, cRange As Range
Dim LastRow As Long, LastRow2 As Long
Dim wb As Workbook, wb2 As Workbook
Set wb = ActiveWorkbook
LastRow = wb.Sheets("2016").Cells(Rows.Count, "A").End(xlUp).Row
Set cRange = wb.Sheets("2016").Range("M2:M" & LastRow)
If Application.WorksheetFunction.CountIf(cRange, "") > 0 Then
Set wb2 = Workbooks.Add
wb.Sheets("2016").Range("A1:M2").Copy wb2.Sheets(1).Range("A2")
LastRow2 = wb2.Sheets(1).Cells(Rows.Count, "A").End(xlUp).Row + 1
For Each Cell In cRange
If Cell.Value = "deposit paid" Then
Cell.EntireRow.Copy
wb2.Sheets(1).Range("A" & LastRow2).PasteSpecial xlPasteFormats
wb2.Sheets(1).Range("A" & LastRow2).PasteSpecial xlValues
LastRow2 = LastRow2 + 1
End If
Next Cell
End If
wb2.Sheets(1).Range("A2:A" & LastRow2).Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
End Sub
Any help anyone can provide is very much appreciated.
Many thanks,
Pad