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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,894
Office Version
  1. 365
Platform
  1. Windows
Hello

Here is an example:
Code:
Range("A1").Copy
    Range("A2").PasteSpecial xlValues
 
Upvote 0

SteveO59L

Well-known Member
Joined
Apr 21, 2004
Messages
7,899
Range("E3").Select
Selection.Copy
Range("F3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
 
Upvote 0

yytsunamiyy

Well-known Member
Joined
Mar 17, 2008
Messages
963
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

doofusboy

Well-known Member
Joined
Oct 14, 2003
Messages
1,325
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

NEAnthony

New Member
Joined
Nov 24, 2008
Messages
13
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

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,894
Office Version
  1. 365
Platform
  1. Windows
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,191,683
Messages
5,987,990
Members
440,124
Latest member
dippy_egg

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
Top