VBA: copy of a cells value disregarding the cells formula

NEAnthony

New Member
Joined
Nov 24, 2008
Messages
13
Hi

Picture you have some cells displaying a number based on a formula. When a copy of this cell is made and you then whant to paste only the value into another cell, you use the paste special option i excel.

My question is how do i write this code in VBA? I like to make a button when clicked it copies only the value from one cell to another disregarding that the value is based upon a formula.

Thanks in advance.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hello

Here is an example:
Code:
Range("A1").Copy
    Range("A2").PasteSpecial xlValues
 
Upvote 0
Range("E3").Select
Selection.Copy
Range("F3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
 
Upvote 0
2 possibilities:

1) Use the pastespecial method - See XL help file for explanation
2) Write the code so that:
Range(Your Target range).value = Range(Your Source range).value
 
Upvote 0
Assuming the cell you want to copy is A1 and where you want to copy it is B1:

Code:
    Range("A1").Select
    Selection.Copy
    Range("B1").Select
    Selection.PasteSpecial Paste:=xlPasteValues

When you need something like this, try recording a macro and it will give you the code you need.
 
Upvote 0
Hi

Thanks for all your input.

I stil have a problem. I have following code
Private Sub CommandButton1_Click()
Sheets("Sheet2").Select
Range("C47:AA47").Select
Selection.Copy
Sheets("FPY på Panel").Select
Range("A8").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub

At Range("C47:AA47").Select the program stops with a runtime error '1004' - Select method of Range class failed. What does this mean?
 
Upvote 0
Let's avoid the select, I hope that will overcome the error. Try;

Code:
Private Sub CommandButton1_Click()
    Sheets("Sheet2").Range("C47:AA47").Copy
    Sheets("FPY på Panel").Range("A8").PasteSpecial xlValues
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,874
Members
449,056
Latest member
ruhulaminappu

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