vba excel sub to validate 4 ranges fails sometimes
on 5 sheets, cols AD, AI, AL, AW:BF are dates output as string(10) mm/dd/yyyy
users can update values
the following code succeeds completely on 3 of 5 sheets, missing 1 column on the other two. (one sheet, the last col; one sheet, a col in the middle of a contiguous range).
Has anyone seen this kind of behavior?
xlsm workbook in Office 365 on Windows 7 SP1 64-bit
Private Sub Worksheet_Change(ByVal Target As Range) Dim ws As Worksheet Dim lRow As Long Dim x As Range Dim rng As Range
Set ws = ThisWorkbook.Worksheets("MySheet")
'Set rng = ActiveSheet.Cells
lRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
Set x = ActiveSheet.Union(Range("AD2:AD" & lRow), Range("AI2:AI" & lRow), Range("AL2:AL" & lRow), Range("AW2:BF" & lRow))
For Each c In x If c.Value <> "" And Not IsDate(c) Then c.ClearContents MsgBox "Enter date mm/dd/yyyy." End If Next c End Sub