我写了一个工作簿的代码,有两个工作表,在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
感谢