hello, I was copy cells of a rage to another palace, by VBA in Excel
then I delete origin, but, when I deleting origin, copied cells deleted also.
please tel me why?
hello, I was copy cells of a rage to another palace, by VBA in Excel
then I delete origin, but, when I deleting origin, copied cells deleted also.
please tel me why?
Hello and welcome to the forum,
I don't understand your question... I tried your code but only 2 cells (J2 and J3) are deleted, not the copied cells
Also, why do you use Pastespecial? You could simple copy-paste? Unless you only want to copy values, formulas, etc...
Here are a few examples of your code that you can try:
Sub Test1()
'No need to select cells...
Dim rng As Range
Set rng = Sheet_Hazer.Range(Cells(2, 10), Cells(3, 12)) 'You copy 6 cells
rng.Copy
Sheet_Hazer.Cells(2, 13).PasteSpecial 'Why using pastespecial?
Sheet_Hazer.Range(Cells(2, 10), Cells(3, 10)).Value = "" 'you are only delete 2 cells!
End Sub
Sub Test2()
'Simpler
Sheet_Hazer.Range("J2:L3").Copy
Sheet_Hazer.Range("M2").PasteSpecial xlPasteValues 'Paste only values
Sheet_Hazer.Range("J2:L3").ClearContents
End Sub
Sub Test3()
'Even simpler
With Sheet_Hazer
.Range("J2:L3").Copy
.Range("M2").PasteSpecial xlPasteValues
.Range("J2:L3").ClearContents
End With
End Sub
Sub Test4()
'No paste special
With Sheet_Hazer
.Range("J2:L3").Copy .Range("M2")
.Range("J2:L3").ClearContents
End With
End Sub
Display More
thank's, solved by your response.
Pleased to help
How is that more efficient than the line of code that I provided? Are you copying cells that have formulas in them?
Don’t have an account yet? Register yourself now and be a part of our community!