Run-Time error '1004':

geoub

New Member
Joined
Mar 21, 2011
Messages
4
Hi,

I am trying to copy a value from one cell to another cell in another worksheet and get this error.
application-defined or object-defined error

Here is my code: (basically I create a macro and made a few changes to it)
Sub CopyAndPaste() 'copy and paste service code number
Sheets("data").Select
Range("A1").Select
Selection.Copy
ActiveCell.Offset(1, 0).Select
Sheets("CopyPaste").Select
Range("C4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveCell.Offset(3, 0).Select
Do
Sheets("Data").Select
Selection.Copy
ActiveCell.Offset(1, 0).Select

Sheets("CopyPaste").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveCell.Offset(3, 0).Select
Application.CutCopyMode = False
Sheets("data").Select
Loop Until IsEmpty(ActiveCell)

End Sub

Any help would be appreciated.

Thanks!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
What line is it erroring on?

Also, what are you wanting to do with this code?
 
Upvote 0
Sorry

Its the second line:
Range("A1").select

I am trying to copy a cell from worksheet "data" and paste it into worksheet "copypaste".

thanks
 
Upvote 0
Given I followed your code properly, try (btw, welcome to the forums!)

Code:
Sub CopyAndPaste() 'copy and paste service code number
Dim i       As Long, _
    LR      As Long, _
    rowx    As Long
 
rowx = 4
LR = Sheets("Data").Range("A" & rows.Count).End(xlUp).row
Application.ScreenUpdating = False
For i = 1 To LR
    Sheets("Data").Range("A" & i).Copy
    Sheets("CopyPaste").Range("C" & rowx).PasteSpecial Paste:=xlPasteValues
    rowx = rowx + 3
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0
works great, thanks a lot!

couple of questions:
1. why was I getting the above error?
2. how can I tweak your code to add more cells? (I copy and pasted the code multiples times for every cell I wanted to do it for)
 
Upvote 0
Honestly, I have no idea why it was giving you an error on that line.

As far as including cells, it all depends what cells you want to include and where you want them pasted to. If they are contiguous, that makes reworking the code incredibly easy. However, if they are noncontiguous, it might requires a bit of recoding.
 
Upvote 0
Might be because you did 'sheets().select', sometimes it needs 'sheets().activate', or sometimes if likes an activeworkbook there too if there's a select.
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,847
Members
452,948
Latest member
UsmanAli786

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