Copying values in a Macro

WatfordKev

Board Regular
Joined
Mar 30, 2011
Messages
78
I am copying values from one sheet to another using a Macro. The values come across OK, but I also want to copy the formatting of the cell. I.e. the sheet2 cell value may be a percentage, integer etc., which I also need to be copied to the sheet1 cell.

Example
sheet1.Range("B73") = sheet2.Range("K" & value)

In this scenario, the sheet2 value may be 20% but the sheet1 value ends up as 0.2
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
sheet2.Range("K" & value).Copy Destination:=sheet1.Range("B73")
 
Upvote 0
that is brilliant, thank you very much. By way of icing on the cake as it were, Is there any way to retain the visual formatting of the destination cell, i.e. only transfer the 'Number' formatting?
 
Upvote 0
Try:
Code:
Sheet1.Range("A1").Copy
Sheet3.Range("A1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
...changing ranges to suit. Just as FYI, you can get this by recording the steps, just make sure to save in This Workbook.
 
Upvote 0
You can also do what you want this way...

Code:
Sheet1.Range("B73").Value = Sheet2.Range("K" & value).Value
Sheet1.Range("B73").NumberFormat = Sheet2.Range("K" & value).NumberFormat
 
Upvote 0

Forum statistics

Threads
1,224,551
Messages
6,179,480
Members
452,915
Latest member
hannnahheileen

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