Question

Locked

How do i know the current format of cell in excel?

By sprema ·
Actually i need to display a calendar in which cell has the format as date. I got a code to display the calendar,
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If IsDate(ActiveCell.Value) Then

With Calendar1
.Visible = True
.Left = ActiveCell.Left + ActiveCell.Width
.Top = ActiveCell.Top
.Value = ActiveCell.Value
End With
Else
Calendar1.Visible = False
End If
End Sub


in this its responding when it has the date value but i need the cells in which cell has the date format..

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

Check the NumberFormat

by belmhorst In reply to How do i know the current ...

Here is a handy little function that might do the trick for you. Right now I am just checking a static range and putting text in it whether or not it is formatted as a date. Give that a try and post back if you need to.


Function FindMyDates()
Dim cCell As Range

For Each cCell In Range("A1:C5")
If cCell.NumberFormat = "m/d/yyyy" Then
'Place your code here
cCell.Value = "Date"
Else
'Place other code here if you want
cCell.Value = "Date"
End If
Next
End Function

Related Discussions

Related Forums