deepakgoyal2005
Board Regular
- Joined
- Sep 1, 2008
- Messages
- 58
I have an excel workbook with multiple sheets having data in Table format with exactly same columns. Need to combine data from all into 1 Table.
Sample:
Sheet "Sheet1" has a table under name "Table1" with 3 columns.
Similarly, Sheet "Sheet2" has a table under name "Table2" with same 3 columns.
And, likewise there could be more sheets added/removed in future.
There is another Sheet "SheetC" with similar table "TableC" where a combined output with data from other table needs to be created.
Trying to create a macro to loop through all the tables except the output combined table "TableC" and append the records in output "TableC". But I am facing trouble creating a loop. Tried googling through available samples, but they were not using data in table format, and hence were of little help.
Would really appreciate, if someone could help with their expertise. Thanks in advance.
VBA macro (WIP):
Sample:
Sheet "Sheet1" has a table under name "Table1" with 3 columns.
Sr. No. | Name | Login ID |
1 | Name 1 | Login 1 |
2 | Name 2 | Login 2 |
3 | Name 3 | Login 3 |
4 | Name 4 | Login 4 |
5 | Name 5 | Login 5 |
Similarly, Sheet "Sheet2" has a table under name "Table2" with same 3 columns.
Sr. No. | Name | Login ID |
6 | Name 6 | Login 6 |
7 | Name 7 | Login 7 |
8 | Name 8 | Login 8 |
9 | Name 9 | Login 9 |
10 | Name 10 | Login 10 |
11 | Name 11 | Login 11 |
And, likewise there could be more sheets added/removed in future.
There is another Sheet "SheetC" with similar table "TableC" where a combined output with data from other table needs to be created.
Trying to create a macro to loop through all the tables except the output combined table "TableC" and append the records in output "TableC". But I am facing trouble creating a loop. Tried googling through available samples, but they were not using data in table format, and hence were of little help.
Would really appreciate, if someone could help with their expertise. Thanks in advance.
VBA macro (WIP):
VBA Code:
Sub Combine_Tables()
'
' Consolidate data from Multiple tables
'
Dim NextRow As Long 'To identify the last blank row in combined table
' Clear content in output combined table
ActiveWorkbook.Sheets("Combine").Range("TableC").ClearContents
'Copy content from first "Table1"
ActiveWorkbook.Sheets("Sheet 1").Select
Range("Table1").Select
Selection.Copy
ActiveWorkbook.Sheets("Combine").Select
Range("B3").Select
Selection.End(xlDown).Select
Range("B8").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub