Hi,
I'm trying to do a merge of 2 filtered tables into a 3rd one.
Here is a simple example of what I'm trying to do. I have 3 sheets (Husband_Expenses, Wife_Expenses, Family_House_Expenses) and each sheet has a table (Husband_Expenses_T, Wife_Expenses_T, Family_House_Expenses_T) that contains rows of expense data.
Both the Husband_Expenses_T and Wife_Expenses_T, have an Expense_Type column that I can use to filter the expenses to show only the ones I want to see (for example, House, Car, Food, etc.)
I've been able to use the following code to merge both Husband_Expenses_T and Wife_Expenses_T into a 3rd table that contains all records so essentially a Family_Expenses_T. But I would like to filter both these tables first so that I only copy rows that have Expense_Type with a value of "House" into Family_House_Expenses_T table on the Family_House_Expenses sheet.
Sub Populate_Family_House_Expenses_T()
Dim lastRow As Variant
Dim mySheets
mySheets = Array("Husband_Expenses", "Wife_Expenses")
Family_House_Expenses_T 'This function empties the table in case it currently contains data.
For i = 0 To UBound(mySheets)
Set lastRow = Sheets("Family_House_Expenses").ListObjects("Family_House_Expenses_T").ListRows.Add
Sheets(mySheets(i)).ListObjects(mySheets(i) & "_T").DataBodyRange.Copy
lastRow.Range.PasteSpecial xlPasteValues
Next i
End Sub
Can someone point me in the right direction?
Thanks.
I'm trying to do a merge of 2 filtered tables into a 3rd one.
Here is a simple example of what I'm trying to do. I have 3 sheets (Husband_Expenses, Wife_Expenses, Family_House_Expenses) and each sheet has a table (Husband_Expenses_T, Wife_Expenses_T, Family_House_Expenses_T) that contains rows of expense data.
Both the Husband_Expenses_T and Wife_Expenses_T, have an Expense_Type column that I can use to filter the expenses to show only the ones I want to see (for example, House, Car, Food, etc.)
I've been able to use the following code to merge both Husband_Expenses_T and Wife_Expenses_T into a 3rd table that contains all records so essentially a Family_Expenses_T. But I would like to filter both these tables first so that I only copy rows that have Expense_Type with a value of "House" into Family_House_Expenses_T table on the Family_House_Expenses sheet.
Sub Populate_Family_House_Expenses_T()
Dim lastRow As Variant
Dim mySheets
mySheets = Array("Husband_Expenses", "Wife_Expenses")
Family_House_Expenses_T 'This function empties the table in case it currently contains data.
For i = 0 To UBound(mySheets)
Set lastRow = Sheets("Family_House_Expenses").ListObjects("Family_House_Expenses_T").ListRows.Add
Sheets(mySheets(i)).ListObjects(mySheets(i) & "_T").DataBodyRange.Copy
lastRow.Range.PasteSpecial xlPasteValues
Next i
End Sub
Can someone point me in the right direction?
Thanks.