VBA Code to Copy data is giving error

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
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try

Code:
LR = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row
Sheets("Sheet2").Range("A1:O" & LR).Copy Destination:=Sheets("MainSheet").Range(ColumnStart)
 
Upvote 0

Forum statistics

Threads
1,215,761
Messages
6,126,735
Members
449,333
Latest member
Adiadidas

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