excel VBA,sheet1有很多类似的数据,我想通过三个特定的条件把sheet1中所有行数据找出来显示在shheet2 50

PrivateSubCommandButton1_Click()Range("A20:P100").ClearContentsi=2j=20date1=Format(Ce... Private Sub CommandButton1_Click()
Range("A20:P100").ClearContents
i = 2
j = 20
date1 = Format(Cells(1, 1), "YYYYMMDD")
date2 = Format(Cells(2, 1), "hh:mm:ss")
Money = Cells(3, 1)
With Sheets("Sheet1")
Do Until .Cells(i, 4) = ""
aa = Right(.Cells(i, 4), 8)
If date1 = aa Then
bb = Format(.Cells(i, 5), "hh:mm:ss")
Dim chazhi As Integer
cc = Val(.Cells(i, 6))
dd = Val(Money)
chazhi = Val(DateDiff("n", date2, bb))
jine = Val(dd - cc)
If -5 < chazhi And chazhi < 5 And -2 < jine And jine < 2 Then
For n = 1 To 15
Cells(j, n) = .Cells(i, n)
Next n
j = j + 1
End If
End If
i = i + 1
Loop
End With
End Sub
这个怎么查找不出来
展开
 我来答
pieryon
2018-03-08 · 知道合伙人数码行家
pieryon
知道合伙人数码行家
采纳数:14410 获赞数:166872
获取软件设计师高级职称 万达金融最佳创新奖

向TA提问 私信TA
展开全部
计算日期差值错了。
Private Sub CommandButton1_Click()
Range("A20:P100").ClearContents
i = 2
j = 20
date1 = Format(Cells(1, 1), "YYYYMMDD")
date2 = Format(Cells(2, 1), "hh:mm:ss")
Money = Cells(3, 1)
With Sheets("Sheet1")
Do Until .Cells(i, 4) = ""
aa = Right(.Cells(i, 4), 8)
If date1 = aa Then
bb = Format(.Cells(i, 5), "hh:mm:ss")
Dim chazhi As Integer
cc = Val(.Cells(i, 6))
dd = Val(Money)
chazhi = Val(DateDiff("d", date2, bb))
jine = Val(dd - cc)
If (chazhi > -5 And chazhi < 5) And (jine > -2 And jine < 2 ) Then
For n = 1 To 15
Cells(j, n) = .Cells(i, n)
Next n
j = j + 1
End If
End If
i = i + 1
Loop
End With
End Sub
追问
我要按照分钟误差来查找,不是按照天
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式