excelgal2016
New Member
- Joined
- Dec 14, 2016
- Messages
- 21
- Office Version
- 2019
- Platform
- Windows
Hi all,
I have the below code and this is what I want to achieve:
IF L1=1 AND B1="" AND C1=""
then I want to prevent the file from saving. In all the other scenarios, the file should be saved. I need to also be able to specific Sheet name.
This code works but it disregards cell C1. I also want to be able to add more cells that can't be blank if required.
Anyone who can help?
Thank you
I have the below code and this is what I want to achieve:
IF L1=1 AND B1="" AND C1=""
then I want to prevent the file from saving. In all the other scenarios, the file should be saved. I need to also be able to specific Sheet name.
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If (Sheets("Sheet1").[L1] = "1" And Sheets("Sheet1").[B1] = "" And Sheets("Sheet1").[C1] = "") Then
Cancel = True
MsgBox "Save disabled. Custom message comes here"
Else
Cancel = False
End If
End Sub
This code works but it disregards cell C1. I also want to be able to add more cells that can't be blank if required.
Anyone who can help?
Thank you