Proper way of doing copy and paste code to run in the background?

rolando87

New Member
Joined
Mar 13, 2017
Messages
20
Office Version
  1. 2010
Platform
  1. Windows
Hey guys, sorry im stuck on this small issue. I'd like to copy and paste a row but not copy paste the values only, id like to copy the formulas as well just like you would do a normal ctrl-C and ctrl-V function on excel. The current code I have works perfectly fine for pasting values but not for pasting the formula as well. I tried variations along these lines .Range("G2:Y2").Copy = .Range("G4:Y4") but it doesn't work. I'd like to insert the code right below .Range("A4:F4").Value = .Range("A2:F2").Value

I'm simply trying to copy cells G2-Y2 and paste them in G4-Y4

Here is the full code

VBA Code:
Public ninetyPrev_Val As Variant
Private Sub Worksheet_Calculate()
    Dim ninetyF2 As Range

    With ThisWorkbook.Sheets("90 Min Bars")
        Set ninetyF2 = .Range("F2")
    
        If ninetyF2.Value <> ninetyPrev_Val Then
            Application.EnableEvents = False
            Application.ScreenUpdating = False
        
            .Rows("4:4").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
            .Range("A4:F4").Value = .Range("A2:F2").Value

     ;      .Range("G2:y2").Copy = .Range("G2:y2") copy and paste code would go here
        
            Application.ScreenUpdating = True
            Application.EnableEvents = True
        End If
    End With

    ninetyPrev_Val = ninetyF2.Value

End Sub


Anyone have any ideas, thanks very much
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
You're a legend! works perfectly, seriously this forum has been so helpful i'm like dumbfounded at the generosity!
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,537
Members
449,088
Latest member
RandomExceller01

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