bradyman97
Board Regular
- Joined
- Feb 22, 2008
- Messages
- 60
- Office Version
- 2019
I advance filter data in sheet called Invoices and filter (First Code Below) it to sheet called Warehouse_Invoices. Then I copy and paste Warehouse_Invoices to sheet WAREHOUSE_Inventory last row plus one. How can I combine the two VBA codes below into one code? I want the new code to paste to the last row plus one.
First Code
Sub Copy_Warehouse_Invoices()
Dim rg As Range
Set rg = ThisWorkbook.Worksheets("Warehouse_Invoices").Range("A7").CurrentRegion
rg.Offset(1).ClearContents
Dim rgInvoices As Range, rgCriteria As Range, rgWarehouse_Invoices As Range
Set rgInvoices = ThisWorkbook.Worksheets("Invoices").Range("A1").CurrentRegion
Set rgCriteria = ThisWorkbook.Worksheets("Warehouse_Invoices").Range("A1").CurrentRegion
Set rgWarehouse_Invoices = ThisWorkbook.Worksheets("Warehouse_Invoices").Range("A7").CurrentRegion
rgInvoices.AdvancedFilter xlFilterCopy, rgCriteria, rgWarehouse_Invoices
Second Code
Sub Filter_Warehouse_Invoices_To_WAREHOUSE_Inventory()
Dim sht1 As Worksheet
Dim sht2 As Worksheet
Dim rng As Range
Set sht1 = Worksheets("Warehouse_Invoices")
Set sht2 = Worksheets("WAREHOUSE_Inventory")
With sht1
Set rng = .Range("A8", .Range("A8").End(xlDown))
Set rng = .Range(rng, rng.End(xlToRight))
End With
rng.Copy
sht2.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial
First Code
Sub Copy_Warehouse_Invoices()
Dim rg As Range
Set rg = ThisWorkbook.Worksheets("Warehouse_Invoices").Range("A7").CurrentRegion
rg.Offset(1).ClearContents
Dim rgInvoices As Range, rgCriteria As Range, rgWarehouse_Invoices As Range
Set rgInvoices = ThisWorkbook.Worksheets("Invoices").Range("A1").CurrentRegion
Set rgCriteria = ThisWorkbook.Worksheets("Warehouse_Invoices").Range("A1").CurrentRegion
Set rgWarehouse_Invoices = ThisWorkbook.Worksheets("Warehouse_Invoices").Range("A7").CurrentRegion
rgInvoices.AdvancedFilter xlFilterCopy, rgCriteria, rgWarehouse_Invoices
Second Code
Sub Filter_Warehouse_Invoices_To_WAREHOUSE_Inventory()
Dim sht1 As Worksheet
Dim sht2 As Worksheet
Dim rng As Range
Set sht1 = Worksheets("Warehouse_Invoices")
Set sht2 = Worksheets("WAREHOUSE_Inventory")
With sht1
Set rng = .Range("A8", .Range("A8").End(xlDown))
Set rng = .Range(rng, rng.End(xlToRight))
End With
rng.Copy
sht2.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial