Pasting a value into a cell losses formula

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
Office Version
  1. 2007
Platform
  1. Windows
Hi,

I run the code below.

Code:
Private Sub CommandButton1_Click()Sheets("INCOME1").Range("C30:F30").Copy
Sheets("INCOME2").Range("C4:F4").PasteSpecial Paste:=xlPasteValues
Sheets("INCOME2").Activate
ActiveSheet.Range("A5").Select
Sheets("INCOME1").Activate
ActiveSheet.Range("H32").Select
ActiveWorkbook.Save


End Sub

The sheet that the code is pasted to has a formula in cell E4
The formula is,

Code:
=IF(C4="","",C4+D4)

This formula is lost upon paste.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
You are pasting into C4:F4 this would paste over E4 since it is in the range.
 
Upvote 0
You can't have a formula and a value in a cell at the same time. When you paste the C30:F30 range into the C4:F4 range, the pasted value overwrites the formula. This macro copies only the values from columns C, D and F of "INCOME1" and pastes those values to columns C, D and F of "INCOME2" leaving the formula in E4 in place.

Code:
Private Sub CommandButton1_Click()
    With Sheets("INCOME1")
        .Range("C30:D30").Copy
        Sheets("INCOME2").Range("C4").PasteSpecial Paste:=xlPasteValues
        .Range("F30").Copy
        Sheets("INCOME2").Range("F4").PasteSpecial Paste:=xlPasteValues
    End With
    Application.CutCopyMode = False
    ActiveWorkbook.Save
End Sub
 
Upvote 0
Yes you are correct and it now makes sense to forget about cell E

many thanks
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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