VBA Copy Formulas then Paste Value

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,342
Office Version
  1. 365
Platform
  1. Windows
I have code that copies a formula down a range. I want to past the Values over the formulas once they are calculated.

Do I have to recopy the paste area and then do a Paste Value? or can this be done in one step?
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Application.ScreenUpdating = False

    Dim LastRow As Long
'
    LastRow = ActiveWorkbook.ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row
'
    Range("J8").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(AND(RC3<>"""",R[-3]C3<>"""",RC8<>""""),EOMONTH(R5C3,RC8),"""")"
    Range("K8").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(AND(RC3<>"""",R5C3<>"""",RC9<>"""",RC10<>""""),EOMONTH(RC10,RC9),"""")"
'
    Range("J8:K8").Select
    Selection.Copy
'
        With ActiveWorkbook.ActiveSheet
            .Range("J8:K" & LastRow).PasteSpecial Paste:=xlPasteFormulas
            End With
'
    Application.CutCopyMode = False
    Range("H8").Select
'
End Sub
 
Last edited by a moderator:

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Untested, but try
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Application.ScreenUpdating = False

    Dim LastRow As Long
'
    LastRow = ActiveWorkbook.ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row
'
    Range("J8:J" & LastRow).FormulaR1C1 = _
        "=IF(AND(RC3<>"""",R[-3]C3<>"""",RC8<>""""),EOMONTH(R5C3,RC8),"""")"
    Range("K8:K" & LastRow).FormulaR1C1 = _
        "=IF(AND(RC3<>"""",R5C3<>"""",RC9<>"""",RC10<>""""),EOMONTH(RC10,RC9),"""")"
    Range("J8:K" & LastRow).Value = Range("J8:K" & LastRow).Value
    Range("H8").Select
'
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,192
Messages
6,129,432
Members
449,509
Latest member
ajbooisen

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