subrahmanyam85
New Member
- Joined
- Aug 26, 2014
- Messages
- 20
Hi,
I am trying to copy data from Sheet1, Sheet2 into MainSheet by using below code.
I can able to copy the data of Sheet1, but while copying data of Sheet2 is giving error "Application defined or Object Defind error".
Below is my code.
==================================================
Private Sub Test()
Application.ScreenUpdating = False
'Get Calculation Status
Dim LastLine As Long
Dim ColumnStart As String
Dim ColumnEnd As String
'Copy Sheet1 into MainSheet
Sheets("Sheet1").Columns("A:O").Copy Destination:=Sheets("MainSheet").Range("A1")
'Get the Last row from MainSheet to append
LastLine = Worksheets("MainSheet").Range("A" & Rows.Count).End(xlUp).Row
ColumnStart = "A"
ColumnStart = ColumnStart + CStr(LastLine + 1)
'ColumnEnd = "O"
'ColumnEnd = ColumnEnd + CStr(LastLine + 1)
MsgBox ColumnStart
'MsgBox ColumnEnd
'Copy Sheet2 into MainSheet
Sheets("Sheet2").Columns("A:O").Copy Destination:=Sheets("MainSheet").Range(ColumnStart)
End Sub
I am trying to copy data from Sheet1, Sheet2 into MainSheet by using below code.
I can able to copy the data of Sheet1, but while copying data of Sheet2 is giving error "Application defined or Object Defind error".
Below is my code.
==================================================
Private Sub Test()
Application.ScreenUpdating = False
'Get Calculation Status
Dim LastLine As Long
Dim ColumnStart As String
Dim ColumnEnd As String
'Copy Sheet1 into MainSheet
Sheets("Sheet1").Columns("A:O").Copy Destination:=Sheets("MainSheet").Range("A1")
'Get the Last row from MainSheet to append
LastLine = Worksheets("MainSheet").Range("A" & Rows.Count).End(xlUp).Row
ColumnStart = "A"
ColumnStart = ColumnStart + CStr(LastLine + 1)
'ColumnEnd = "O"
'ColumnEnd = ColumnEnd + CStr(LastLine + 1)
MsgBox ColumnStart
'MsgBox ColumnEnd
'Copy Sheet2 into MainSheet
Sheets("Sheet2").Columns("A:O").Copy Destination:=Sheets("MainSheet").Range(ColumnStart)
End Sub