Loop not quite working correctly
Hi Howard,
Am Wed, 27 May 2015 07:23:34 -0700 (PDT) schrieb L. Howard:
What I was shooting for was to make the code adaptable to the length of column A.
then insert a variable LastRow:
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
End If
End If
MsgBox vMsg, vbInformation
End Sub
Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
|