I have a macro that copies data from one sheet and pastes values to another. Everything seems good but I received the error:
Run-time Error 1004: Application-defined or object-defined Error
I simplified the code for your convenience because the whole macro is a set of similar codes:
Sub CopyPaste()
Sheets("Primary").Select
Range("A1").Select
Selection.Copy
Sheets("Result").Range("A2").End(xlToRight).Offset(, 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
The debugger shows the problem with the row:
Sheets("Result").Range("A2").End(xlToRight).Offset(, 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
I really don't understand what's wrong here. Almost the same code works with another Excel spreadsheet.
I went through similar questions here but couldn't find any that help me. So, maybe it's easy for VBA Professionals but not for me. It's only my second week using VBA, for this reason any help is very appreciated.
SkipBlankson to two lines, as you demonstrate here? Also since you're just doing the values, try this instead of copy (your whole sub can be one line):Sheets("Result").Range("A2").End(xlToRight).Offset(0,1).Value = Sheets("Primary").Range("A1").ValueRange("A2").End(xlToRight).Address? It's possible you've reached the literal end (last column) of the worksheet, therefore theOffset(,1)will fail.Copy/PasteSpecialif all you're doing is values, just do a direct value assignment: stackoverflow.com/questions/17281872/…