ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA Date Format Cell Check (https://www.excelbanter.com/excel-programming/403005-vba-date-format-cell-check.html)

Kim

VBA Date Format Cell Check
 
Hi,

I'm trying to check cells for Date format or not, but the code below isn't
working properly. Despite confirming the Date format in the cells being
checked, my code isn't running the command (ActiveCell.Offset(1, 0).Activate
Instead, it's branching to the Else command, which I do not want. This seems
simple, can someone help?

If ActiveCell.NumberFormat = "Date" Then
ActiveCell.Offset(1, 0).Activate
Else
ActiveCell.Select
Selection.Cut
ActiveCell.Offset(-1, 1).Activate
ActiveSheet.Paste
ActiveCell.Offset(1, -1).Activate
End If



Thanks!
Kim

Mike H

VBA Date Format Cell Check
 
Maybe

If IsDate(ActiveCell.Value) Then
Stop
ActiveCell.Offset(1, 0).Activate
Else
ActiveCell.Select
Selection.Cut
ActiveCell.Offset(-1, 1).Activate
ActiveSheet.Paste
ActiveCell.Offset(1, -1).Activate
End If


Mike

"Kim" wrote:

Hi,

I'm trying to check cells for Date format or not, but the code below isn't
working properly. Despite confirming the Date format in the cells being
checked, my code isn't running the command (ActiveCell.Offset(1, 0).Activate
Instead, it's branching to the Else command, which I do not want. This seems
simple, can someone help?

If ActiveCell.NumberFormat = "Date" Then
ActiveCell.Offset(1, 0).Activate
Else
ActiveCell.Select
Selection.Cut
ActiveCell.Offset(-1, 1).Activate
ActiveSheet.Paste
ActiveCell.Offset(1, -1).Activate
End If



Thanks!
Kim


Mike H

VBA Date Format Cell Check
 
Or have i misunderstood, do you mean

If ActiveCell.NumberFormat = "mm/dd/yyyy" Then

Mike

"Kim" wrote:

Hi,

I'm trying to check cells for Date format or not, but the code below isn't
working properly. Despite confirming the Date format in the cells being
checked, my code isn't running the command (ActiveCell.Offset(1, 0).Activate
Instead, it's branching to the Else command, which I do not want. This seems
simple, can someone help?

If ActiveCell.NumberFormat = "Date" Then
ActiveCell.Offset(1, 0).Activate
Else
ActiveCell.Select
Selection.Cut
ActiveCell.Offset(-1, 1).Activate
ActiveSheet.Paste
ActiveCell.Offset(1, -1).Activate
End If



Thanks!
Kim



All times are GMT +1. The time now is 03:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com