vba,用于搜索与“查找最近日期”匹配的值
我为一个有两个工作表的工作簿编写了一个代码,在“a”列的ProximoPedido(sheet)中有一个a值范围(整数),在colunm“B”中有一个关联的日期,在ChekingList(sheet)中有一个colunm“a”和值(必须与ProximoPedido的“a”匹配)以及colunm“E”和日期。如果检查表单元格A的值与ProximoPeddo的“A”值匹配,则在检查表的“E”中搜索ProximoPeddo的下一个(或最近的更高)日期“B” 工作表:检查表 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:20 24--------------------2009-10-28 10:20vba,用于搜索与“查找最近日期”匹配的值,vba,date,find,next,Vba,Date,Find,Next,我为一个有两个工作表的工作簿编写了一个代码,在“a”列的ProximoPedido(sheet)中有一个a值范围(整数),在colunm“B”中有一个关联的日期,在ChekingList(sheet)中有一个colunm“a”和值(必须与ProximoPedido的“a”匹配)以及colunm“E”和日期。如果检查表单元格A的值与ProximoPeddo的“A”值匹配,则在检查表的“E”中搜索ProximoPeddo的下一个(或最近的更高)日期“B” 工作表:检查表 A-------------
3------------------------------------------2009-10-28 10:20在代码中设置两个变量
DIM MatchCell as Range
Dim Targetdelta匹配为双精度
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