How to Apply VBA PasteSpecial and Keep Source Formatting in Excel: 4 Easy Examples

Method 1 – Add Input Box by Using VBA PasteSpecial and Keep Source Formatting in Excel

  • Press  Alt  F11   to start a Macro.
  • Click on the Insert, choose the Module option.

Add Input Box by Using VBA PasteSpecial and Keep Source Formatting in Excel

  • Paste the following VBA code.
Sub PasteSpecialKeepFormat()
'declare CopyCell and PasteCell as range variable
Dim CopyCell As Range, PasteCell As Range
'Give a name to the Input Box
xTitleId = "ExcelDemy"
'Set copy range will be selected from the worksheet
Set CopyCell = Application.Selection
'Set a Input Box to take a range to copy from
Set CopyCell = Application.InputBox("Select Range to Copy :", xTitleId, CopyCell.Address, Type:=8)
'Set a Input Box to take a range to paste to
Set PasteCell = Application.InputBox("Paste to any blank cell:", xTitleId, Type:=8)
'Command to copy the selected range
CopyCell.Copy
'Command to paste the range
PasteCell.Parent.Activate
'command to pasted cells to keep the source formatting
PasteCell.PasteSpecial xlPasteValuesAndNumberFormats
PasteCell.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
End Sub

Add Input Box by Using VBA PasteSpecial and Keep Source Formatting in Excel

  • Save the program and press  F5   to run it.
  • After appearing in the ‘ExcelDemy’ box, select the range $B$4:$C$11.
  • Click OK.

Add Input Box by Using VBA PasteSpecial and Keep Source Formatting in Excel

  • Select any blank cell to paste.
  • Click OK.

Add Input Box by Using VBA PasteSpecial and Keep Source Formatting in Excel

  • You will get the paste value by keeping the format intact.

Add Input Box by Using VBA PasteSpecial and Keep Source Formatting in Excel

 


Method 2 – Apply VBA PasteSpecial to Select Range and Keep Source Formatting in Excel

  • Press  Alt  F11  to open Macro.
  • Create a new Module from the Insert
  • Paste the following VBA code for the range B4:C11.
Sub pasteSpecial_KeepFormat()
'select range to copy
Range("B4:C11").Copy
'select cell to paste
'Command to pasteSpecial keeping the Format
Range("E4").PasteSpecial xlPasteAllUsingSourceTheme
End Sub

Add Input Box by Using VBA PasteSpecial and Keep Source Formatting in Excel

  • Save the program and press  F5  to run. Add Input Box by Using VBA PasteSpecial and Keep Source Formatting in Excel

 


Method 3 – Declare Variable by Applying VBA PasteSpecial and Keep Source Formatting in Excel

  • Press  Alt  F11  to open VBA Macro.
  • Select a new Module.
  • Paste the following VBA Code.
Sub Copy_Paste_Special()
'Declare variables
Dim copy_Rng As Range, Paste_Range As Range
'Command to copy range
Set copy_Rng = Range("B4:C11")
'Command to paste range
Set Paste_Range = Range("E4")
copy_Rng.Copy
'Paste command to pasteSpecial with keeping Format
Paste_Range.PasteSpecial Paste:=xlPasteAllUsingSourceTheme
End Sub

Add Input Box

  • After saving the program, press  F5  to run.
  • Your copied range will be pasted with keeping the source formatting as before.

Add Input Box


Method 4 – Use VBA PasteSpecial and Keep Source Formatting in Different Worksheet in Excel

  • Oopen VBA Macro, press  Alt  + F11
  • From the Insert tab, choose the Module.
  • Paste the following VBA.
Private Sub KeepSourceFormat()
  Application.ScreenUpdating = False
  'Declare variables
  Dim copyRng As Worksheet
  Dim pasteRng As Worksheet
 'Set range destination to the variable
  Set copyRng = Worksheets("Sheet4")
  Set pasteRng = Worksheets("Sheet5")
  'set the destination of the pasted cells
  'For cell E4, Rows.count = 5, Offset = 3
  Set Destination = pasteRng.Cells(Rows.Count, 5).End(xlUp).Offset(3, 0)
  'Command to copy the range
  copyRng.Range("B4:C11").Copy
 'Command to paste the range
   Destination.PasteSpecial Paste:=xlPasteValues
   Destination.PasteSpecial Paste:=xlPasteFormats
  Application.CutCopyMode = False
  Application.ScreenUpdating = True
End Sub

Add Input Box

  • Run the program, press  F5  after saving the program.
  • Get the pasted value in sheet 5 while keeping the source format.

Add Input Box

 


Download Practice Workbook

Download this workbook to practice.


Related Articles

Get FREE Advanced Excel Exercises with Solutions!
Bhubon Costa
Bhubon Costa

Bhubon Costa, B.Sc. in Naval Architecture & Marine Engineering from Bangladesh University of Engineering & Technology, has worked with the ExcelDemy since 2021. Currently, he has been working as a reviewer. Notably, he has written over 90 articles and led several VBA content development teams. He has a great passion for the fields of data analytics and data science. His areas of expertise include Excel VBA, Power Query, Pivot Table, Power BI, MySQL, PostgreSQL, machine learning, and Python... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo