2013-07-01 77 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