|
这个帖子我几天前发过,是grf1973大师给做的。现在是求查询代码,如果能把下面的代码修改成查询代码更好。恳请大师帮忙,谢谢!
Sub 保存()With Sheets("各店日报表")
If [c4] = "" Then MsgBox "《单位名称》不能为空!": Exit Sub
If [f4] = "" Then MsgBox "《日期》不能为空!": Exit Sub
If [d23] = "" Then MsgBox "《请输入内容》!不能为空!": Exit Sub
rmax = .[a65536].End(3).Row
For r = 6 To rmax
If .Cells(r, 1) = [c4] And .Cells(r, 2) = [f4] Then
yn = MsgBox("您已经保存过了!重新保存等于修改?", vbYesNo)
If yn = vbNo Then Exit Sub
Exit For
End If
Next
.Cells(r, 1) = [c4]: .Cells(r, 2) = [f4]
For K = 6 To 22
.Cells(r, 3 * K - 15) = Cells(K, 4)
.Cells(r, 3 * K - 15 + 1) = Cells(K, 6)
.Cells(r, 3 * K - 14 + 1) = Cells(K, 7)
s = s + Cells(K, 6)
Next
.Cells(r, 54) = s
.Cells(r, 55) = Date
MsgBox "记录已保存在第" & r & "行!"
End With
End Sub
- Sub 查询()
- With Sheets("各店日报表")
- If [c4] = "" Then MsgBox "《单位名称》不能为空!": Exit Sub
- If [f4] = "" Then MsgBox "《日期》不能为空!": Exit Sub
- rmax = .[a65536].End(3).Row
- For r = 6 To rmax
- If .Cells(r, 1) = [c4] And .Cells(r, 2) = [f4] Then Exit For
- Next
- If r <= rmax Then
- For K = 6 To 22
- Cells(K, 4) = .Cells(r, 3 * K - 15)
- Cells(K, 6) = .Cells(r, 3 * K - 15 + 1)
- Cells(K, 7) = .Cells(r, 3 * K - 14 + 1)
- Next
- Else
- MsgBox "未找到匹配记录"
- End If
- End With
- End Sub
复制代码
|
|