我寫了一個工作簿的代碼,有兩個工作表,在ProximoPedido(表)列「A」中有一個值的範圍(整數)和colunm「B」中有一個相關日期,並且在ChekingList(表單)中存在具有值(必須與ProximoPedido的「A」匹配)的柱狀「A」和具有日期的柱狀「E」。如果CheckingList的單元格A的值與ProximoPedido的「A」的值匹配,則在ChekingList的「E」中搜索ProximoPedido的下一個(或最接近的更高)日期「B」。vba如果它匹配找到最接近的日期
表:CheckingList
A -------------------------------------- --- E
1 ---------------------------------- 2009-10-30 12: 00
3 --------------------------------- 2009-10-29 13:00
2 --------------------------------- 2009-10-29 12:20
50-- ------------------------------ 2009-10-19 10:2 0
24 -------------------------------- 2009-10-28 10:20
3 ---------------------------------- 2009-10-28 10:20 < ------ - ( 比賽!)
表:關閉請求
的------------------------------------乙----
4 ---------------------------------- 2009-10-28 10 :20
20 --------------------------------- 2009-10-29 13:00
---------------------------------- 3 2009-10-19 15:20
24 --------------------------------- 2009-10-29 13點40
3 ----------------------------------- 2009-10-27 13: < ------------ 20(例如)
公式我寫的第一和調理與VLOOKUP與其他折射率匹配,但VLOOKUP給了我checkinglist所有日期的最後一個值,然後,我想這代碼:Sub TempoTotal1()在你的代碼
Dim CheckingList As Worksheet
Dim ProximPedido As Worksheet
Dim tear1 As Range
Dim inicio As Range
Dim tear2 As Range
Dim saida As Range
Dim diferença As Range
Dim cell1 As Range
Dim cell2 As Range
Dim i As Integer
Set tear1 = Worksheets("CheckingList").Range("a2").CurrentRegion
Set inicio = Worksheets("CheckingList").Range("e2").CurrentRegion
Set tear2 = Worksheets("ProximoPedido").Range("a1").CurrentRegion
Set saida = Worksheets("ProximoPedido").Range("b2").CurrentRegion
Set diferença = Worksheets("ProximoPedido").Range("c2").CurrentRegion
On Error Resume Next
For Each cell1 In tear1
If tear1.Cells.Value = tear2.Cells.Value Then
For Each cell2 In inicio
If tear2.Cells.Value > saida.Cells.Value Then
diferença.Cells.Value = inicio.Cells.Value - saida.Cells.Value
End If
Exit For
Next cell2
End If
Exit For
Next cell1
End Sub
感謝