Loop not quite working correctly
Hi again,
Am Wed, 27 May 2015 16:31:33 +0200 schrieb Claus Busch:
then insert a variable LastRow:
and you have to put the line with the MsgBox into the IF statement or
you always have a MsgBox. If all cells are filled the MsgBox has not
text:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim myCnt As Long, Diff As Long
Dim OneRng As Range, rngC As Range, sBlanks$, vMsg
'Modify the last expected row in column A
Const LastRow = 200
Set OneRng = Range("A1:A" & LastRow)
myCnt = Application.CountA(OneRng)
If Len(Cells(LastRow + 1, 1)) = 0 Then Cells(LastRow + 1, 1) = "End"
Diff = 200 - myCnt
If Not ThisWorkbook.Saved Then
If Diff 0 Then
Cancel = True
MsgBox "Cells A1 to A" & LastRow & " " & _
" must have values before " _
& vbCr & " the workbook is closed or saved!" _
& vbCr & vbCr & _
" " & Diff & _
" cells are empty!", vbExclamation, "Blank Cells Alert"
sBlanks = OneRng.SpecialCells(xlCellTypeBlanks).Address(0, 0)
sBlanks = Join(Split(sBlanks, ","), Chr(10))
vMsg = "Blanks cells a" & vbLf & vbLf & sBlanks
MsgBox vMsg, vbInformation
End If
End If
End Sub
Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
|