Merge Cell Data from multiple tabs to one master tab

jiangmojia

New Member
Joined
Jan 10, 2018
Messages
2
Hello,

I try to merge the data from multiple tabs to one master tab. Since the concepts in those tabs constantly updated every day (always adding the new information), I want to make sure my master tab is always up to date, and include all updated concepts. Below is the coding I came up with in VBA. However, I could not run it in Excel since the coding underlined was always showed a debug issue. Could somebody look at my coding and let me know how to fix it?

Much appreciated. Lucy

Sub MergeDataFromWorksheets()
Dim sh As Worksheet
Dim DestShe As Worksheet
Dim erow As Long, lrowsh As Long, Startrow As Long
Dim CopyRng As Range
Startrow = 2
With Application
.ScreenUpdating = False
.EnableEvents = False
End With

'Delete the sheet "MyMergeSheet"
Application.DisplayAlerts = False
On Error Resume Next
ActiveWorkbook.Worksheets("MyMergeSheet").Delete
On Error GoTo 0
Application.DisplayAlerts = True

'Add a worksheet with the name "MyMergeSheet"
Set DestSh = ActiveWorkbook.Worksheets.Add
DestSh.Name = "MyMergeSheet"
'loop through all worksheets and copy the data to the DestSh
For Each sh In ActiveWorkbook.Worksheets
If shtName <> DestSh.Name Then
'Find the next blank or empty row on the DestSh
erow = DestSh.Range("A" & Rows.Count).End(x1UP).Offset(1, 0).Row
'Find the last row with data in the Sheet
lrowsh = sh.Range("A" & Rows.Count).End(xlUp).Row

Set CopyRng = sh.Range(sh.Rows(Startrow), sh.Rows(lrowsh))

'copies values/formats
CopyRng.Copy
With DestSh.Cells(erow, 1)
.PasteSpecial x1PasteValues
.PasteSepcial x1PasteFormates
Application.CutCopyMode = faluse

End With

End If
Next

DestSh.Cells(1, 1) = "Current Period Update"
DestSh.Cells(1, 2) = "Deficiency Reference #"
DestSh.Cells(1, 3) = "Audit Report Number"
DestSh.Cells(1, 4) = "IA Reference #"
DestSh.Cells(1, 5) = "Identifier"
DestSh.Cells(1, 6) = "Control Matrix Ref. #"
DestSh.Cells(1, 7) = "Category"
DestSh.Cells(1, 8) = "Region"
DestSh.Cells(1, 9) = "Location"
DestSh.Cells(1, 10) = "Control Activity"
'AutoFit the column width in the DestSh sheet
DestSh.Columns.AutoFit

With Application
.ScreeUpdating = True
.EnableEvents = True
End With
End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top