Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
vba,用于搜索与“查找最近日期”匹配的值_Vba_Date_Find_Next - Fatal编程技术网

vba,用于搜索与“查找最近日期”匹配的值

vba,用于搜索与“查找最近日期”匹配的值,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-------------

我为一个有两个工作表的工作簿编写了一个代码,在“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:20


3------------------------------------------2009-10-28 10:20在代码中设置两个变量

  • 第一个将跟踪单元格位置
    DIM MatchCell as Range
  • 第二个将跟踪源单元格和源单元格之间的增量 将单元格
    Dim Targetdelta匹配为双精度
  • 现在,循环查看Sheet上的数据:Proximo Pedido执行以下逻辑步骤

  • 计算当前单元格上的日期与检查表中的日期之间的绝对差值
  • 如果该增量小于Targetdelta的当前值
  • 然后将增量更新为新值,并在MatchCell变量中记录当前地址
  • 继续循环
  • 在循环之后,您知道哪个单元格最近-它存储在MatchCell变量中
  •     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