using predefined names in VBA

Viewed 120

The code is really simple and I'm just trying to copy values in from_range and paste them in to_range. But it's just not working out...

Sub test14()
    Range("to_range") = Range("from_range")
End Sub

Before,

Before

After, not sure why everything in to_range is gone

After

Desired, just want to overwrite to_range with from_range

Desired

Could someone explain what's going on here? Thanks.

2 Answers

also you can do this job with Select:

Range("from_range").Select
Selection.Copy
Range("to_range").Select
ActiveSheet.Paste

I solved the question coping the range and pasting special like explained above:

Sub test14()
    Range("from_range").Copy
    Range("to_range").PasteSpecial xlPasteValues
End Sub

I hope it helps you!

Regards, Pedro Azzam.

Related