

So yeah guys, this is how you can merge every sheet in a workbook. This loops runs for all the sheets and copies each sheets data into master sheet.įinally, in the end of the macro we activate the mastersheet to see the output. We pasted it directly into first blank cell after last non blank cell in column A of master sheet (mtr.Cells(Rows.Count, 1).End(xlUp).Row + 1).

Range(Cells(startRow, startCol), Cells(lastRow, lastCol)).Copy We have copied it using copy method of range. Range(Cells(startRow, startCol), Cells(lastRow, lastCol)) We have done multiple operations into one line.įirst we form a range using startRow, startCol and lastRow and lastCol. Then we get last row and last column number. Then we exclude “master” sheet from looping, since we will be consolidating our data in that sheet. Here we are looping through each sheet in main workbook using for loop. In earlier articles we learned how to loop through sheets and how to get last row and column using vba. Let’s look at the main part of this vba code. Well most of the things I have explained using comments in vba code. in the first part we have created object and variables that we will need in our operations. I assume that you know the basics of object and variable creation in VBA. Select the heading and hit OK.Īnd it is done.

Range(Cells(startRow, startCol), Cells(lastRow, lastCol)).Copy _ 'get data from each worksheet and copy it into Master sheet LastCol = Cells(startRow, Columns.Count).End(xlToLeft).Column LastRow = Cells(Rows.Count, startCol).End(xlUp).Row Set headers = Application.InputBox("Select the Headers", Type:=8)

Other sheet names doesn’t matter.ĭim startRow, startCol, lastRow, lastCol As Long I have added one more sheet and named it as “Master”. Here I have fetched some data from server that returns data into different worksheets. This articles will tell you how to merge multiple worksheets into one worksheet using VBA. Sometimes we want to merge multiple sheets into one sheet so that we can easily analyse the data and turn it into some useful information.
