You are on page 1of 3

Excel Work Book

Formulae No - 01
Formulae Name : VBA Code "Sub GetSheets()"
Use Full for : You can use VBA scripts to combine multiple workbook into one master workbook
Click Developer > Visual Basic, a new Microsoft Visual Basic for applications window will be
displayed, click Insert > Module, and input the following code into the Module:

Sub GetSheets()
Path = "C:\Users\dt\Desktop\dt kte\"
Filename = Dir(Path & "*.xls")
Do While Filename <> ""
Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
For Each Sheet In ActiveWorkbook.Sheets
Sheet.Copy After:=ThisWorkbook.Sheets(1)
Next Sheet
Filename = Dir()
End Sub
Tip: In the above code, you can change the path to the one that you are using.
Then click button to run the code, and all of the worksheets (including the blank worksheets
within the workbooks have been merged into the master workbook.

Note: This VBA code can merge the entire workbooks into the master workbook, if you want to
combine specified worksheets of the workbooks, this code will not work.

Any Other Info :

Formulae No - 02
Formulae Name : VBA Code " MakeSummaryTable()"
Use Full for : This will copy all of the C1 cells in all worksheets to column-A in sheet1. Rename the sheet
references per your workbook.

Sub MakeSummaryTable()
Dim ws As Worksheet

Application.ScreenUpdating = False

For Each ws In Worksheets

If ws.Name <> "Sheet1" Then
ActiveSheet.Paste Range("A65536").End(xlUp).Offset(1, 0)
End If
Next ws

Application.ScreenUpdating = True

End Sub

Any Other Info :

Formulae No - 03
Formulae Name : VBA Code " SortWorkBook()"
Use Full for : Sort Worksheets In Alphabetical / Alphanumeric Order With VBA Code

Sub SortWorkBook()
Dim xResult As VbMsgBoxResult
xTitleId = "KutoolsforExcel"
xResult = MsgBox("Sort Sheets in Ascending Order?" & Chr(10) & "Clicking No will sort
in Descending Order", vbYesNoCancel + vbQuestion + vbDefaultButton1, xTitleId)
For i = 1 To Application.Sheets.Count
For j = 1 To Application.Sheets.Count - 1
If xResult = vbYes Then
If UCase$(Application.Sheets(j).Name) > UCase$(Application.Sheets(j +
1).Name) Then
Sheets(j).Move after:=Sheets(j + 1)
End If
ElseIf xResult = vbNo Then
If UCase$(Application.Sheets(j).Name) < UCase$(Application.Sheets(j +
1).Name) Then
Application.Sheets(j).Move after:=Application.Sheets(j + 1)
End If
End If
End Sub