Table of Contents
VBA (Visual Basic for Applications) is a programming language that can be used to automate tasks and processes in Microsoft Excel. One useful feature of VBA is the ability to copy and paste data while preserving its original formatting. This means that any special formatting, such as font styles, colors, and cell borders, will be maintained when the data is pasted. This can be achieved by using the “PasteSpecial” method in VBA, which allows for the selection of specific formatting options to be applied when pasting data. By utilizing this feature, users can efficiently transfer data between different worksheets or workbooks while ensuring the integrity of the original formatting is maintained. This can save time and effort, especially when dealing with large amounts of data.
VBA: Paste Values and Keep Formatting
You can use the following syntax in VBA to copy a range of cells and paste the values along with the source formatting to a new location:
Sub PasteWithFormatting()
Range("A1:C11").Copy
Range("A13").PasteSpecial Paste:=xlPasteAllUsingSourceTheme
Application.CutCopyMode = False
End Sub
This particular macro will copy the cells in the range A1:C11 and paste the values from the cells with their formatting into the range starting at cell A13.
Note: The line Application.CutCopyMode = False specifies that the cut and copy mode should be turned off after running the macro.
The following example shows how to use this syntax in practice.
Example: Paste Values and Keep Formatting Using VBA
Suppose we have the following dataset in Excel that contains information about various basketball players:

Suppose we would like to copy and paste all of the values in the range A1:C11 to a new location and keep the formatting.
We can create the following macro to do so:
Sub PasteWithFormatting()
Range("A1:C11").Copy
Range("A13").PasteSpecial Paste:=xlPasteAllUsingSourceTheme
Application.CutCopyMode = False
End SubWhen we run this macro, we receive the following output:

Notice that the values from the original cells have been pasted with their formatting into the cell range starting at cell A13.
Note: You can find the complete documentation for the VBA PasteSpecial method here.
Cite this article
stats writer (2024). How can I use VBA to paste values and maintain the formatting of the original data?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-paste-values-and-maintain-the-formatting-of-the-original-data/
stats writer. "How can I use VBA to paste values and maintain the formatting of the original data?." PSYCHOLOGICAL SCALES, 21 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-paste-values-and-maintain-the-formatting-of-the-original-data/.
stats writer. "How can I use VBA to paste values and maintain the formatting of the original data?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-paste-values-and-maintain-the-formatting-of-the-original-data/.
stats writer (2024) 'How can I use VBA to paste values and maintain the formatting of the original data?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-paste-values-and-maintain-the-formatting-of-the-original-data/.
[1] stats writer, "How can I use VBA to paste values and maintain the formatting of the original data?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can I use VBA to paste values and maintain the formatting of the original data?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
