CrazyBritGuy
New Member
- Joined
- Dec 10, 2019
- Messages
- 13
- Office Version
- 2016
- Platform
- Windows
I've got a list object that has a column that contains dates. I need to determine which column(s) contains dates.
I've tried using DataBodyRange.NumberFormat, TypeName, and IsDate. I expected TypeName to return "Date" and ISDate expecting "True" but I got:
using this code:
I don't want to rely on testing the number format "m/d/yyyy" since the users may decide they want the date displayed using the ISO format, "yyyy/mm/dd", or some other format. (As we know dates can be shown in many formats.)
I thought that either TypeName or ISDate would work, why don't they work? What alternative approach can I take that does not require testing for all the date display formats?
I've tried using DataBodyRange.NumberFormat, TypeName, and IsDate. I expected TypeName to return "Date" and ISDate expecting "True" but I got:
using this code:
VBA Code:
If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
If ActiveSheet.ListObjects.Count <> 1 Then Exit Sub
Set oLobj = ActiveSheet.ListObjects(1)
For Each oLc In oLobj.ListColumns
MsgBox _
"oLc.DataBodyRange.NumberFormat" & vbTab & vbTab & "= " & oLc.DataBodyRange.NumberFormat & vbCrLf & _
"TypeName(oLc.DataBodyRange.Value2(1, 1))" & vbTab & "= " & TypeName(oLc.DataBodyRange.Value2(1, 1)) & vbCrLf & _
"IsDate(oLc.DataBodyRange.Value2(1, 1))" & vbTab & "= " & IsDate(oLc.DataBodyRange.Value2(1, 1))
Next oLc
I don't want to rely on testing the number format "m/d/yyyy" since the users may decide they want the date displayed using the ISO format, "yyyy/mm/dd", or some other format. (As we know dates can be shown in many formats.)
I thought that either TypeName or ISDate would work, why don't they work? What alternative approach can I take that does not require testing for all the date display formats?