![]() |
Trap a DateValue Error
Excel 2003, WinXP Home
In VBA: I want to validate the ActiveCell entry for a date. I learned before that the IsDate function finds a valid date in just about everything. I learned to use the DateValue(ActiveCell) for this purpose. But the only way I can see to trap the error is to use an On Error GoTo Err trap and set the DateValue to something like: a = DateValue(ActiveCell) to force an error. That works fine but it seems a round-about way to get there. What I was hoping for was something like: If IsError(DateValue(ActiveCell)) Then........ But this triggers a Type Mismatch. How do I trap the error without the round-about method above? Thanks for your help. Otto |
Trap a DateValue Error
On Error Resume Next
a = DateValue(ActiveCell) if err.Number < 0 then msgbox "Invalid date" err.Clear ' not really needed if On Error Goto 0 is used as below End if On Error goto 0 -- Regards, Tom Ogilvy "Otto Moehrbach" wrote in message ... Excel 2003, WinXP Home In VBA: I want to validate the ActiveCell entry for a date. I learned before that the IsDate function finds a valid date in just about everything. I learned to use the DateValue(ActiveCell) for this purpose. But the only way I can see to trap the error is to use an On Error GoTo Err trap and set the DateValue to something like: a = DateValue(ActiveCell) to force an error. That works fine but it seems a round-about way to get there. What I was hoping for was something like: If IsError(DateValue(ActiveCell)) Then........ But this triggers a Type Mismatch. How do I trap the error without the round-about method above? Thanks for your help. Otto |
Trap a DateValue Error
Thanks Tom. Saved me again. I have a spare bedroom if you want to just
move in. <g Otto "Tom Ogilvy" wrote in message ... On Error Resume Next a = DateValue(ActiveCell) if err.Number < 0 then msgbox "Invalid date" err.Clear ' not really needed if On Error Goto 0 is used as below End if On Error goto 0 -- Regards, Tom Ogilvy "Otto Moehrbach" wrote in message ... Excel 2003, WinXP Home In VBA: I want to validate the ActiveCell entry for a date. I learned before that the IsDate function finds a valid date in just about everything. I learned to use the DateValue(ActiveCell) for this purpose. But the only way I can see to trap the error is to use an On Error GoTo Err trap and set the DateValue to something like: a = DateValue(ActiveCell) to force an error. That works fine but it seems a round-about way to get there. What I was hoping for was something like: If IsError(DateValue(ActiveCell)) Then........ But this triggers a Type Mismatch. How do I trap the error without the round-about method above? Thanks for your help. Otto |
All times are GMT +1. The time now is 05:12 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com