Seamus2626
asked on
Add some copy code
Hi, i have a sub below, i need to add to more sheets to the tab "All", however i do not want their headings to transfer over and i need the first to append to the current data, and the next to append below the second data.
Basically im merging three tabs of data onto one tab called "All"
Thanks
Sub MergeTabs()
Sheets.Add.Name = "All"
Set Wss = Workbooks("CurrentMonth.xl sx").Works heets("Out bound")
Set Wst = Workbooks("CurrentMonth.xl sx").Works heets("All ")
Wss.UsedRange.Copy Destination:=Wst.Cells(1, 1)
End Sub
Basically im merging three tabs of data onto one tab called "All"
Thanks
Sub MergeTabs()
Sheets.Add.Name = "All"
Set Wss = Workbooks("CurrentMonth.xl
Set Wst = Workbooks("CurrentMonth.xl
Wss.UsedRange.Copy Destination:=Wst.Cells(1, 1)
End Sub
The attached file has the following code...
This should provide a direction to go in.
Any questions feel free to ask.
ATB
Steve.
C--Users-shall-Desktop-Example.xlsm
Dim wsDestination As Worksheet
Sub merge()
Set wsDestination = Sheets("ALL")
Call CopyFromSheet(Sheets("Outbound1"))
Call CopyFromSheet(Sheets("Outbound2"))
Call CopyFromSheet(Sheets("Outbound3"))
End Sub
Sub CopyFromSheet(wsSource As Worksheet)
Dim FromRange As Range
Set FromRange = wsSource.Range("A2:F" & wsSource.Range("A" & Rows.Count).End(xlUp).Row)
FromRange.Copy wsDestination.Range("A" & wsDestination.Range("A" & Rows.Count).End(xlUp).Row + 1)
End Sub
This should provide a direction to go in.
Any questions feel free to ask.
ATB
Steve.
C--Users-shall-Desktop-Example.xlsm
The below is a slight variation on the code to include creation of the sheet and addition of the header row:
Dim wsDestination As Worksheet
Sub merge()
On Error Resume Next
Application.DisplayAlerts = False
Sheets("ALL").Delete
Application.DisplayAlerts = True
On Error GoTo 0
Set wsDestination = Sheets.Add
wsDestination.Name = "ALL"
Sheets("Outbound1").Range("A1:F1").Copy Sheets("ALL").Range("A1:F1")
Call CopyFromSheet(Sheets("Outbound1"))
Call CopyFromSheet(Sheets("Outbound2"))
Call CopyFromSheet(Sheets("Outbound3"))
End Sub
Sub CopyFromSheet(wsSource As Worksheet)
Dim FromRange As Range
Set FromRange = wsSource.Range("A2:F" & wsSource.Range("A" & Rows.Count).End(xlUp).Row)
FromRange.Copy wsDestination.Range("A" & wsDestination.Range("A" & Rows.Count).End(xlUp).Row + 1)
End Sub
C--Users-shall-Desktop-Example.xlsm
ASKER
Thanks Steve,
I have amended my code slightly and am getting the error "Object Required" on line
FromRange.Copy wsDestination.Range("A" & wsDestination.Range("A" & Rows.Count).End(xlUp).Row + 1)
It looks exactly the same as yours, can you see why i would get this error?
Thanks
-------------------------
Sub merge()
On Error Resume Next
Application.DisplayAlerts = False
Sheets("Combined Data").Delete
Application.DisplayAlerts = True
On Error GoTo 0
Set wsDestination = Sheets.Add
wsDestination.Name = "Combined Data"
Sheets("Incountry").Range( "A1:AT1"). Copy Sheets("Combined Data").Range("A1:AT1")
Call CopyFromSheet(Sheets("Inco untry"))
Call CopyFromSheet(Sheets("Inbo und"))
Call CopyFromSheet(Sheets("Outb ound"))
End Sub
Sub CopyFromSheet(wsSource As Worksheet)
Dim FromRange As Range
Set FromRange = wsSource.Range("A2:AT" & wsSource.Range("A" & Rows.Count).End(xlUp).Row)
FromRange.Copy wsDestination.Range("A" & wsDestination.Range("A" & Rows.Count).End(xlUp).Row + 1)
End Sub
I have amended my code slightly and am getting the error "Object Required" on line
FromRange.Copy wsDestination.Range("A" & wsDestination.Range("A" & Rows.Count).End(xlUp).Row + 1)
It looks exactly the same as yours, can you see why i would get this error?
Thanks
-------------------------
Sub merge()
On Error Resume Next
Application.DisplayAlerts = False
Sheets("Combined Data").Delete
Application.DisplayAlerts = True
On Error GoTo 0
Set wsDestination = Sheets.Add
wsDestination.Name = "Combined Data"
Sheets("Incountry").Range(
Call CopyFromSheet(Sheets("Inco
Call CopyFromSheet(Sheets("Inbo
Call CopyFromSheet(Sheets("Outb
End Sub
Sub CopyFromSheet(wsSource As Worksheet)
Dim FromRange As Range
Set FromRange = wsSource.Range("A2:AT" & wsSource.Range("A" & Rows.Count).End(xlUp).Row)
FromRange.Copy wsDestination.Range("A" & wsDestination.Range("A" & Rows.Count).End(xlUp).Row + 1)
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect, thanks Steve!!
ASKER
Sub MergeTabs()
Sheets.Add.Name = "All"
Set OutB = Workbooks("CurrentMonth.xl
Set InB = Workbooks("CurrentMonth.xl
Set InC = Workbooks("CurrentMonth.xl
Set Wst = Workbooks("CurrentMonth.xl
OutB.UsedRange.Copy Destination:=Wst.Cells(1, 1)
InB.UsedRange.Copy Destination:=Wst.Cells(1, 1)
InC.UsedRange.Copy Destination:=Wst.Cells(1, 1)