查找date列

我是新的VBA,我正在尝试编写一个macros,它将查找包含数据中的date的列,并在其旁边select一个列。

date是这样的:

Date output 01/02/2011 200 02/02/2011 200 03/02/2011 200 

我努力了:

 Sub Macro5() With ActiveSheet.Cells .Find(what:=vbDate).Select End With ActiveCell.Offset(0, 1).Select ActiveCell.EntireColumn.Select End Sub 

但并不像预期的那样工作。 任何人都可以给我一个解决scheme吗?

下面是一个search格式的演示

 Sub Demo() Dim rng As Range Dim rngDate As Range ' Set reference to search range by whatever means Set rng = ActiveSheet.UsedRange ' Setup search Application.FindFormat.Clear Application.FindFormat.NumberFormat = "m/d/yyyy" ' Do search Set rngDate = rng.Find(What:="*", SearchFormat:=True) ' report result If Not rngDate Is Nothing Then MsgBox "Found a Date formated cell in column " & rngDate.Column End If End Sub 

下面的代码在活动工作表中searchdate。 只要它find一个,它会select它旁边的列并停止。

 Dim rng As Range For Each rng In ActiveSheet.UsedRange If IsDate(rng.Value) Then rng.Offset(0, 1).EntireColumn.Select Exit Sub End If Next 

下面是一个例子,它search第2行格式化为date的单元格(假设任何date至less包含date,即stringd ):

 Dim i As Long With Sheet1.Range("2:2") ' or wherever you want to search For i = 1 To .Columns.Count With .Cells(1, i) If InStr(.NumberFormat, "d") <> 0 Then .Offset(0, 1).EntireColumn.Select Exit For End If End With Next i End With