Ironman
Well-known Member
- Joined
- Jan 31, 2004
- Messages
- 1,069
- Office Version
- 365
- Platform
- Windows
Hi
I have the below code that opens a msgbox and creates a "1" in H1 when a named cell falls between 2 values
Cell H1 is then cleared when the workbook closes with this code (which I'm not convinced is as efficient below the 8th line as it could be - suggestions for improvement would be welcomed)
I'm wondering if there's a more efficient way of creating a msgbox when a value is reached without having to generate a digit and then removing it?
Many thanks!
I have the below code that opens a msgbox and creates a "1" in H1 when a named cell falls between 2 values
VBA Code:
If Range("No_MILES_RUN_SINCE_1981") > 27990 And Range("No_MILES_RUN_SINCE_1981") < 28000 Then
If [H1] = "" Then
MsgBox "You're now approaching 28,000 miles!", vbInformation, "Miles Run Since 16.04.1981"
[H1] = "1"
End If
End If
Cell H1 is then cleared when the workbook closes with this code (which I'm not convinced is as efficient below the 8th line as it could be - suggestions for improvement would be welcomed)
VBA Code:
Private Sub workbook_beforeclose(Cancel As Boolean)
Application.DisplayAlerts = True
Worksheets("Training Log").[G1:Z1] = vbNullString
Application.EnableEvents = True
MsgBox "New backup files created in" & vbNewLine & vbNewLine _
& "E:\BACKUPS\EXERCISE LOG " & vbNewLine & vbNewLine _
& "Y:\DOCUMENTS\EXERCISE LOG\EXIT BACKUPS" & vbNewLine & vbNewLine _
& "Exercise Log will now close", vbInformation, "Master File Overwritten"
ThisWorkbook.Saved = True
Application.EnableEvents = True
'If Application.Workbooks.Count < 2 Then
' ThisWorkbook.Close False
' Application.Quit 'close Excel application and this workbook
'Else
'no need to save it twice
' ThisWorkbook.Close False
'End If
End Select
Application.EnableEvents = True
End Sub
Many thanks!