Elite Membership

VBA Paste Values

Written by Jeevan A Y Jeevan A Y Freelance Writer Jeevan, a seasoned data expert with 7 years in MIS reporting, excels in Advanced Excel, VBA, Power BI, and SQL. Currently an Assistant Manager MIS, his insightful data storytelling drives swift decision-making. 7+ years of experience MBA (Finance & Marketing) MIS Reporting View Full Profile
Reviewed by Dheeraj Vaidya, CFA, FRM Dheeraj Vaidya, CFA, FRM Content Reviewer & Course Director A former J.P.Morgan and CLSA Equity Analyst, Dheeraj specializes in financial modeling, AI, forecasting, and valuations. In his career spanning almost two decades, he has trained and mentored more than 100,000 students and professionals on a range of topics. 20+ years of experience CFA, FRM, IIT Delhi, IIM Lucknow Financial Modeling View Full Profile
Updated Dec 23, 2024
Read Time 4 min

Excel VBA Paste Values

Copy and paste is not the greatest job in the world! But copying and pasting with special options requires some knowledge in VBA. It is not a straightforward process as a simple copy and paste. One of the important paste special methods is โ€œPaste Valuesโ€ in VBA.

Download FREE VBA Paste Values In Excel Template and Follow Along!
Download Excel Template

How to Paste Values in Excel using VBA?

Example #1 – Using Paste Special

Look at the below worksheet image.

VBA Paste Value Example 1

In cell B6, we applied the formula to calculate the total sales values from B2 to B5. Therefore, if we copy and paste cell B6 to C6, we will not get the value of 22,761, but we will get the corresponding formula.

To carry out the same thing in VBA, we need coding knowledge. We will show you how to paste values using VBA. Follow the below steps.

Step 1: Copy the cell B6.

To copy cell B6, use the code Range (โ€œB6โ€).Copy

VBA Paste Value Example 2-1

Step 2: Select the destination cell. In this case, C6 cell.

As you can see after the copy, it asks, “Destination.” It is nothing but where you want to paste, so select the “Destination” as Range (“C6”).

Code:

Sub Paste_Values() ย Range(“B6”).Copy Range(“C6”) End Sub

Step 3: Run the Code

Run this code we will get the B6 copy in C6.

VBA Paste Value Example 2-2

We got only the formula here.

Step 4: Perform a Paste Special Method.

To perform the PasteSpecial method, let us look at the syntax below the PasteSpecial method.

VBA Paste Value Example 2-3

In the PasteSpecial method, we have several methods. First, based on our operation, we must select the type accordingly.

To understand, let us break the code into two lines.

The first one is copying cell B6.

VBA Paste Value Example 2-4

In the next line, write the destination cell as Range (“C6”).

VBA Paste Value Example 2-5

Now, to access the Paste Special method, put a dot and start typing the letter “P.”

VBA Paste Value Example 2-6

Select the “Paste Special” method in the above variety of options.

VBA Paste Value Example 2-7

After selecting the method, press the space key to see the various Paste Special methods.

VBA Paste Value Example 2-8

In this variety of options, select “xlPasteValues.”

VBA Paste Value Example 2-9

After selecting the option, press the “Tab” key to auto-select.

Code:

Sub Paste_Values() Range(“B6”).Copy Range(“C6”).PasteSpecial xlPasteValues End SubExample 2-10

Step 5: Run the Code

Now, run the code. We should get only the value of cell B6 to cell C6.

Example 2-11

If you notice the worksheet after running the code, it is still in the copy mode.

After executing the Paste Special method, it will disable the cut copy mode.

Example #2 – Paste Special with Loops

Paste Special is easy, but using this as part of a large code requires advanced coding skills.

For example, look at the below image.

Example 3

In the above image of the worksheet in column “F,” we have a total column, i.e., in F2, F5, F8, F11, and F14 cells.

We must copy each total cell from the respective cell and paste it into the column “H” with the individual cells.

Using the below code with VBA loops, we can do this.

Code:

Sub Paste_Values1() Dim k As Integer Dim j As Integer j = 2 For k = 1 To 5 ย  Cells(j, 6).Copy ย  Cells(j, 8).PasteSpecial xlPasteValues ย  j = j + 3 Next k End Sub

This code with the Paste Special option will perform the task of copying each total cell and pasting in the column “H” with individual cells.

Example 3-1

Example #3 – Copy From Worksheet to Another

We need to mention both worksheet names to paste values from one worksheet to another. Below is an example of that.

Sub Paste_Values2() Worksheets(“Sheet1”).Range(“A1”).Copy Worksheets(“Sheet2”).Range(“A15”).PasteSpecial xlPasteValues End Sub

Recommended Articles

This article has been a guide to VBA Paste Values. Here, we discuss the top 3 tips to paste values using the Paste Special method in VBA, along with examples and a downloadable Excel template. Below are some useful Excel articles related to VBA: –