Copying Pasting .... Urgent Help Please

bhagi

New Member
Joined
Jun 27, 2011
Messages
16
Hey
i am getting runtime error 1004 'Application defined or object defined' on running this code can anyone please help... its reallly urgent

Code:
Private Sub CommandButton2_Click()
Dim torow As Long
Dim lastrow As Long
Dim dayCounter As Integer
Dim i, k As Integer

lastrow = Range("A65").End(xlUp).Row

i = Sheet2.Range("A1:A50").Find("Lever 1", Range("A1"), xlValues, xlWhole, xlByColumns, xlNext).Row

i = i + 1


'For dayCounter = 2 To 32

For k = 1 To (lastrow - 1)
 
    Sheet2.Rows(i).Insert Shift:=xlDown

Next

ActiveWorkbook.Sheets(1).Activate
ActiveWorkbook.Sheets(1).Range(Cells(2, "A"), Cells(lastrow, "A")).Select
ActiveWorkbook.Sheets(1).Range(Cells(2, "A"), Cells(lastrow, "A")).Copy
ActiveWorkbook.Sheets(2).Activate
ActiveWorkbook.Sheets(2).Range(Cells((i - 1), "B"), Cells((i + lastrow - 2), "B")).Select
ActiveWorkbook.Sheets(2).Paste


End Sub


Thanks in advance :-)
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
I am sorry, but my workplace has strict policies against downloading files from the internet, so I am afraid I cannot download the file now. There are tools that allow you to post screen prints on this forum (see here: http://www.mrexcel.com/forum/showthread.php?t=508133).

Somehow, I get the feeling that there is some key piece of information that you may be inadvertantly leaving out, especially if that simplified code I gave you does not work on a brand new spreadsheet.

By the way, which version of Excel are you using?
 
Upvote 0
office 2010....
I will send you the screen-shots soon... by the way can it be because of something wrong with my application as in excel itself cuz wen i open it some times it says excel is not responding and after some-time it says
excel foound unreadable content... do you want to recover the contents and wen i click yes it gives me a list of objects (mostly some .xml files) as removed to make the document readable
 
Upvote 0
It is quite possible that you have a corrupt installation of Excel, in which case you may want to try re-installing it. If you have access to another computer, try the code over there and see if it works. If it does, then that would seem to suggest that the issue is PC specific.
 
Upvote 0
I am not sure those shots help, without a description of what is going on. What exactly are you copying from/to?

In any event, did you try the macro on a different computer?

Also when you tried my simplified code on a blank worksheet, and said it didn't work, did you try a blank template of the Excel file/form that you already have, or did you try a brand new blank worksheet?

What I mean is this, try opening a totally blank virgin Excel worksheet. Make sure it has more than one worksheet. On the first sheet, enter values in cell A2:A6. Then run the code below.
Code:
Sub TestCode()
 
Dim i as Long
Dim lastrow as Long
 
i = 5
lastrow = 6
 
ActiveWorkbook.Sheets(1).Activate
ActiveWorkbook.Sheets(1).Range(Cells(2, "A"), Cells(lastrow, "A")).Copy
ActiveWorkbook.Sheets(2).Activate
ActiveWorkbook.Sheets(2).Range(Cells((i - 1), "B"), Cells((i + lastrow - 2), "B")).Select
ActiveWorkbook.Sheets(2).Paste
 
End Sub
There is no way that this code should fail in that scenario. If it does, I suspect you may have a corrupt Excel installation, in which you will need to re-install Excel.
 
Upvote 0
hey thanks a lot ... i tried it and again it gave the same application or object defined error
I guess it must be a problem with my installation of excel.
i ll try in another system and let you know :)
THANKS ATON REALLY
 
Upvote 0
hey!!! i tried it too but it just doesnt work... I mean it is giving the same error the application error.
but wen i see the sheet the data from A2:A6 is highlighted which means it is copying. The only error is occuring in the paste part of the program.
Plz help :) thanks in advance
 
Upvote 0
Since I cannot recreate the error myself, I really have no idea where else to go. Later tonight, when I am home, I can try downloading your file and looking at it. At this point, that is all I can really offer you.
 
Upvote 0

Forum statistics

Threads
1,224,620
Messages
6,179,928
Members
452,949
Latest member
beartooth91

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