Save and Close Unless Any Key Hit

rockyw

Well-known Member
Joined
Dec 26, 2010
Messages
1,196
Office Version
  1. 2010
Platform
  1. Windows
I'm using this code right now but would like to have an additional feature. Can this save and close unless the user hits a key or command button. That way when it opens I can be kept open if someone wants to view it longer. I will have this open, save and close once a day to keep it updated. Thanks


Code:
Private Sub Workbook_Open()
Dim R As Range
Dim Sht As Worksheet
Dim Cel As Range

    Set Sht = Sheets("Data")
    
    Set R = Sht.Range("B4:B27,K4:K27,T4:T27")
    
    For Each Cel In R
        If Cel.Value < 0 Then
            If Cel.Offset(0, 8).Value = "" Then Cel.Offset(0, 8) = Date
        ElseIf Cel.Value >= 0 Then
            Cel.Offset(0, 8).ClearContents
        End If
    Next Cel

    Set R = Sht.Range("T4:T27")
    For Each Cel In R
    If Cel.Value = 0 Then Cel.Offset(0, 9) = Date
    Next Cel
    Set R = Sht.Range("C32:C37")
    For Each Cel In R
    If Cel.Value = 0 Then Cel.Offset(0, 2) = Date
  Next Cel
  
      Selection.ClearComments
      Application.CalculateFull
      ActiveWorkbook.Save
End Sub
 
simple is almost always the best way forward! :)
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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