Hi I amm new to VBA and have managed to patch something together from various excel forums.
I have a case management spread sheet which has a number of rows. The first 9 are mandatory when the spread sheet is 1st completed. Users can subsequently complete the rest of their row as the issue they are dealing with progresses.
I have used the following BeforeClose VBA so it warns them if they haven’t completed the 9 cells we require to but it then comes up with standard excel close dialogue box.
[pre]
[/pre]
The issue is they could ignore and save their changes and therefore mandatory information would be left blank also the next user who may well complete their row correctly will get message relating to someone else’s data which they can see.
Is it possible to stop this and/or apply this to a BeforeSave VBA code at the same time so it works in that scenario also that if they try and save before closing they will get the same message
I have a case management spread sheet which has a number of rows. The first 9 are mandatory when the spread sheet is 1st completed. Users can subsequently complete the rest of their row as the issue they are dealing with progresses.
I have used the following BeforeClose VBA so it warns them if they haven’t completed the 9 cells we require to but it then comes up with standard excel close dialogue box.
[pre]
Code:
Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim rngCell As Range, strBlanks As String
Application.ScreenUpdating = False
strBlanks = vbNullString
For Each rngCell In Worksheets("Sheet1").Range("a2:a2000").Cells
If Len(Trim(rngCell.Value)) > 0 Then
If WorksheetFunction.CountA(rngCell.Offset(0, 1).Resize(1, 9)) < 9 Then
strBlanks = strBlanks & IIf(Len(strBlanks) > 0, ",", "") & _
Replace(rngCell.Offset(0, 1).Resize(1, 9).SpecialCells(xlCellTypeBlanks).Address, "$", "")
End If
End If
Next
If Not strBlanks = vbNullString Then
MsgBox "When initially logging a case entries are mandatory in columns A - J. Please complete entries in the following columns" & vbCrLf & vbCrLf & strBlanks
Cancel = True
Exit Sub
End If
End Sub
The issue is they could ignore and save their changes and therefore mandatory information would be left blank also the next user who may well complete their row correctly will get message relating to someone else’s data which they can see.
Is it possible to stop this and/or apply this to a BeforeSave VBA code at the same time so it works in that scenario also that if they try and save before closing they will get the same message