I am writing a method that can take the Target
and paste the cell exactly to another cell. The cell is a shipping label with some fancy formatting. Is there a way I can do it?
Originally I have this:
Worksheets("Label").Range("A1").Value = Worksheets("Get Address").Range("A28").Value
It worked for the plain text. However I lost the styling I created, they are different because after the first line, the style is different:
I also tried to use Macro Recorder and I got a solution using .Select
, and I read this question not to use it whenever possible. What can I do?
' Created by the Macro Recorder
Range("A28:A33").Select
Range("A33").Activate
Selection.Copy
Sheets("Label").Select
Range("A1").Select
ActiveSheet.Paste
Click Home > Find & Select, and pick Go To Special. Click Visible cells only > OK. Click Copy (or press Ctrl+C). Select the upper-left cell of the paste area and click Paste (or press Ctrl+V).
We can copy a value and paste it to another cell. We can use Paste Special to paste only the values. Similarly, in VBA, we use the copy method with range property to copy a value from one cell to another. We use the worksheet function Paste Special or the paste method to paste the value.
Probably the biggest thing you can do to avoid using Select is to as much as possible, use named ranges (combined with meaningful variable names) in your VBA code.
We use Dot (.) operator to use the copy and paste methods in VBA. We can copy an entire column and paste it to another column and similarly we can also copy an entire row and paste it to another row.
Worksheets("Get Address").Range("A33").Copy _
Destination := Worksheets("Label").Range("A1")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With