Only want to run Code once!

breakbacktennis

New Member
Joined
Aug 30, 2017
Messages
33
Hi, I have some code that I only want to run once. As the sheet it is connected to is refreshing it also keeps refreshing the code thus meaning the code keeps running. Is there anyway just to have the code run once and not keep refreshing?

Code:
Private Sub Worksheet_Calculate()

        If Sheet1.Range("U7").Text = "Done" Then Exit Sub
        If Range("G1").Value = "In-play" Then
               Range("U9").Value = Range("G9").Value
               Range("U11").Value = Range("G11").Value
               Range("U13").Value = Range("C2").Value
        End If
        
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Does this work? Adjust the A1 cell to whatever you want.

Code:
Private Sub Worksheet_Calculate()
    If Range("A1")<>1 Then
        If Sheet1.Range("U7").Text = "Done" Then Exit Sub
        If Range("G1").Value = "In-play" Then
               Range("U9").Value = Range("G9").Value
               Range("U11").Value = Range("G11").Value
               Range("U13").Value = Range("C2").Value
        End If
        Range("A1")=1
    End If
End Sub
 
Upvote 0
Hi Special-K99, Thanks for your post. Unfortunately the macro keeps refreshing along with the spreadsheet. I basically want to take a snapshot of the values in 3 cells as soon as G1 = in-play and then not refresh them if that makes sense.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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