I heart Excel
Board Regular
- Joined
- Feb 28, 2011
- Messages
- 66
Hello,
I have a spreadsheet that other members of staff complete. I have a 11 headers and each header is a mandatory field. The user fills in the spreadsheet with new items to be added to our internal purchasing system.
Everytime the form is opened the user can't save until all required fields are complete.
I do not want this to run unless the user fills in a particular field, such as product code. This is because sometimes the user will open the spreadsheet and amend information they have already added, but are unable to save as the form is assuming they haven't completed the required information for the next row down.
Please see below -
Public LR As Long
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Not Me.Saved Then
Msg = " Are all Mandatory fields Completed?" & vbCr & " 'Yes' will Save the Form" & vbCr & "If you Select 'Yes' and they aren't the Form will Close Without Saving and Completed fields will be Lost"
Ans = MsgBox(Msg, vbQuestion + vbYesNo)
Select Case Ans
Case vbYes
Application.Quit
Case vbNo
Cancel = True
Exit Sub
End Select
ActiveWorkbook.Saved = True
End If
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Application.WorksheetFunction.CountA(Sheet1.Cells(LR + 1, "A").Resize(1, 11)) <> 11 Then
MsgBox "Mandatory fields not Completed, unable to Save" & vbCr & " Please Complete Highlighted Fields", vbOKOnly, "Info"
Cancel = True
End If
End Sub
Private Sub Workbook_Open()
LR = Sheet1.Cells(Rows.Count, "A").End(xlUp).Row
End Sub
Is anyone able to help?
Thanks
I have a spreadsheet that other members of staff complete. I have a 11 headers and each header is a mandatory field. The user fills in the spreadsheet with new items to be added to our internal purchasing system.
Everytime the form is opened the user can't save until all required fields are complete.
I do not want this to run unless the user fills in a particular field, such as product code. This is because sometimes the user will open the spreadsheet and amend information they have already added, but are unable to save as the form is assuming they haven't completed the required information for the next row down.
Please see below -
Public LR As Long
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Not Me.Saved Then
Msg = " Are all Mandatory fields Completed?" & vbCr & " 'Yes' will Save the Form" & vbCr & "If you Select 'Yes' and they aren't the Form will Close Without Saving and Completed fields will be Lost"
Ans = MsgBox(Msg, vbQuestion + vbYesNo)
Select Case Ans
Case vbYes
Application.Quit
Case vbNo
Cancel = True
Exit Sub
End Select
ActiveWorkbook.Saved = True
End If
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Application.WorksheetFunction.CountA(Sheet1.Cells(LR + 1, "A").Resize(1, 11)) <> 11 Then
MsgBox "Mandatory fields not Completed, unable to Save" & vbCr & " Please Complete Highlighted Fields", vbOKOnly, "Info"
Cancel = True
End If
End Sub
Private Sub Workbook_Open()
LR = Sheet1.Cells(Rows.Count, "A").End(xlUp).Row
End Sub
Is anyone able to help?
Thanks