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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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