I created the code as following, but it popup error message.....but I don't know how to debug it.....Sorry that I am new in VBA, please any expert can teach me how to make the code run well, many thanks.
Sub copypaste()'This macro will copy data from worksheets and past to "Target" sheet
Dim nLastCol As Long, nLastRow As Long, i As Long
Dim nTargetLastRow As Long
Dim ws As Worksheet
Dim wsTarget As Worksheet
Dim oriPath As String
dim newPath as string
dim cRange as string
Dim sFil As String
dim oriWS as string
dim newWS as string
Dim thisWB As Workbook
Dim oriWB As Workbook
dim newWB as workbook
With Application
.DisplayAlerts = False
.EnableEvents = False
.ScreenUpdating = False
.CutCopyMode = False '<--------
End With
On Error GoTo 0
Set thisWB = ThisWorkbook
oriPath = thisWB.Sheets("CopySheetCover").Range("A2").Value 'Change to suit
newPath = thisWB.Sheets("CopySheetCover").Range("A5").Value
cRange = thisWB.Sheets("CopySheetCover").Range("A8").Value 'e.g.A:E
Set oriWB = Workbooks.open(oriPath)
Set newWB = Workbooks.open(newPath)
nLastRow = thisWB.Cells(ws.Rows.Count, "A").End(xlUp).Row + 1
For i = 11 to nLastRow
'Define the range and copy
oriWS = thisWB.Sheets("CopySheetCover").Range(i,"A").Value
newWS = thisWB.Sheets("CopySheetCover").Range(i,"B").Value
For Each ws In oriWB.Sheets
If InStr(1, ws.Name, oriWS) Then
ws.columns(cRange).Copy
End If
For Each ws In newWB.Sheets
If InStr(1, ws.Name, newWS) Then
ws.columns(cRange).Paste
End If
next
next
next i
With Application
.DisplayAlerts = True
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub