2013-07-01 79 views
0

所以我有一个excel电子表格,看起来像这样:按特定标准查找特定行? Excel宏,VBA

DATE     | PART#  | XXX | XXX | 

2013-06-28 13:32:23 | 40240  | XXX | XXX | 

2013-02-21 13:32:23 | 40240  | XXX | XXX | 

有许多项,与日期为起点。我的问题是如何找到某一日期的行&列?所以如果我想知道PART#2013-06-28 13:32:23的其他属性,我该如何找到它?

我的MACRO创建一个新工作表,对其进行设置,然后从旧工作表中传输文本。问题在于文本的转移。我想指定从哪个行获取文本以生成报告。

+0

'VLOOKUP'或'INDEX'和'MATCH'功能应该做的伎俩。 –

回答

0

下会发现在搜索值中发现的所有行:

Sub getVal() 
    Dim searchRange As range 
    Dim result As range 
    Dim rangeStart As String 

    Set searchRange = Application.ActiveSheet.UsedRange 
    Set result = searchRange.Find(After:=searchRange(1), _ 
     What:="6/28/2013 1:32:23 PM", _ 
     LookIn:=xlFormulas, SearchDirection:=xlNext) 

    If Not result Is Nothing Then 
     rangeStart = result.Address 

     Do 
      MsgBox (" row " & result(0).Row & " " & result.Address) 
      Set result = searchRange.FindNext(After:=result(1)) 

     Loop While Not result Is Nothing And rangeStart <> result.Address 
    Else 
     MsgBox "Not found" 
    End If 
End Sub