Excel - Merge several worksheets into a single one(thanks)
Closed
jaja599
Posts
1
Registration date
Sunday January 25, 2015
Status
Member
Last seen
January 25, 2015
-
Jan 25, 2015 at 05:39 PM
Linds - Oct 14, 2015 at 05:34 PM
Linds - Oct 14, 2015 at 05:34 PM
Related:
- Excel - Merge several worksheets into a single one(thanks)
- Transfer data from one excel worksheet to another automatically - Guide
- Excel marksheet - Guide
- Number to words in excel - Guide
- Excel apk for pc - Download - Spreadsheets
- Insert gif into excel - Guide
1 response
Write this for myself on Friday for a project of my own:
See if it works for you:
See if it works for you:
Option Explicit
Function WorksheetExists(ByVal WorksheetName As String) As Boolean
Dim Sht As Worksheet
For Each Sht In ThisWorkbook.Worksheets
If Application.Proper(Sht.Name) = Application.Proper(WorksheetName) Then
WorksheetExists = True
Exit Function
End If
Next Sht
WorksheetExists = False
End Function
Sub MergeSheets()
Dim i As Integer
Dim NumberofSheets As Integer
Dim xWs As Worksheet
Dim ActiveSheetLastRow As Long
Dim MergedLastRow As Long
Dim sheetno As Integer
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'Does a sheet called Merge already exist? If so, delete it.
If WorksheetExists("Merge") Then Worksheets("Merge").Delete
' Get a count of the number of sheets in the workbook
NumberofSheets = Application.Sheets.Count
' Create a new sheet to store merged sheets
Worksheets.Add
' Make the new sheet (which is also the active sheet) the last sheet in the workbook.
ActiveSheet.Move After:=Sheets(ActiveWorkbook.Sheets.Count)
'Rename new Sheet
ActiveSheet.Name = "Merge"
'Copy each sheet to the new Office
For i = 1 To NumberofSheets
Set xWs = Sheets(i)
'Find how many rows to copy
ActiveSheetLastRow = xWs.Range("A" & Rows.Count).End(xlUp).Row
'Find the next available row in the Merge sheet
MergedLastRow = Worksheets("Merge").Range("A" & Rows.Count).End(xlUp).Row
' Only copy the header row when copying the 1st sheet.
sheetno = Abs(i > 1) + 1
xWs.Range("A" & sheetno & ":J" & ActiveSheetLastRow).Copy Destination:=Worksheets("Merge").Range("A" & MergedLastRow)
Next i
End Sub
Oct 14, 2015 at 05:34 PM
I would like this same macro to list the name of the worksheet in a row before the data from that worksheet is listed on the new Merge sheet. Can anyone please tell me how to do this?
Thanks in advance for your time -
Lindsey