ProximoPedido (シート) の列 "A" には値の範囲 (整数値) があり、列 "B" には日付が関連付けられています。 ChekingList (シート) には、値の列 "A" (ProximoPedido の "A" と一致する必要があります) と日付の列 "E" があります。CheckingList のセル A の値が ProximoPedido の「A」の値と一致する場合、ProximoPedido からの「B」の次の (または最も近い) 日付を ChekingList の「E」で検索します。
シート: CheckingList
-----------------------------------------------E
1 -------------------------------------------------- 2009-10-30 12:00
3 ----------------------------------2009-10-29 13:00
2---------------------------------2009-10-29 12:20
50--------------------------------2009-10-19 10:20
24--------------------------------2009-10-28 10:20
3 ---------------------------------- 2009-10-28 10:20 <------ - ( マッチ!)
シート: Proximo Pedido
A--------------------------------------------B
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 を条件付けし、その他を INDEX MATCH で条件付けて式を書きましたが、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
ありがとう