Determine if cell in list object contains a date

CrazyBritGuy

New Member
Joined
Dec 10, 2019
Messages
13
Office Version
  1. 2016
Platform
  1. 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:
2021-04-07 15_02_23-Window.png

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?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
What about
VBA Code:
IsDate(oLc.DataBodyRange.Cells(1, 1).Value)
 
Upvote 0
You're welcome. Glad it worked for you. :)
 
Upvote 0

Forum statistics

Threads
1,214,813
Messages
6,121,706
Members
449,049
Latest member
THMarana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top