|
楼主 |
发表于 2024-9-22 11:41
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
首先感谢大神再次出手相助
1.清空”车票出入库“F2单元格是用于您帮我设计的出入库程序中,我在出库、入库的模块中都最后增加了一条”ws.Range("f2").ClearContents“语句,但将单元格内的公式也清除了,不知能知将该条公式也转化为VBA。
公式:IFERROR(INDIRECT("车票结存!I"&$V$1),""),功能就是点击切片器中的姓名时能在F2中显示。
Sub 入库1()
Application.ScreenUpdating = False '关闭屏幕刷新
Dim ar As Variant
Dim br()
Dim rowCount As Long
Dim ws As Worksheet
Set ws = Worksheets("车票出入库")
rs = ws.Cells(Rows.Count, 2).End(xlUp).Row
If rs < 2 Then MsgBox "请先录入数据!": End
ar = ws.Range("a1:b" & rs)
ReDim br(1 To UBound(ar), 1 To 3)
For i = 2 To UBound(ar)
If Trim(ar(i, 2)) <> "" Then
n = n + 1
br(n, 1) = Format(Date, "m-d")
For j = 1 To UBound(ar, 2)
br(n, j + 1) = ar(i, j)
Next j
End If
Next i
If n = "" Then MsgBox "数据源为空,请先录入数据!": End
With ws
r = .Cells(Rows.Count, "h").End(xlUp).Row + 1
.Cells(r, "h").Resize(n, UBound(br, 2)) = br
End With
If Len(ws.[f2].Value) > 0 Then
With Sheets("车票结存")
cr = .[i1].CurrentRegion
dr = Application.Index(cr, 1)
x = Application.Match(ws.[f2].Value, .Columns("i"), 0)
For i = 1 To n
y = Application.Match(br(i, 2), dr, 0)
cr(x, y) = Empty
Next
.[i1].CurrentRegion = cr
End With
End If
ws.Range("B2:B" & rs).ClearContents
ws.Range("f2").ClearContents
Application.ScreenUpdating = True '开启屏幕刷新
End Sub
Sub 出库1()
Application.ScreenUpdating = False '关闭屏幕刷新
Dim ar As Variant
Dim br()
Dim rowCount As Long
Dim ws As Worksheet
Set ws = Worksheets("车票出入库")
rs = ws.Cells(Rows.Count, 3).End(xlUp).Row
If rs < 2 Then MsgBox "请先录入数据!": End
ar = ws.Range("a1:c" & rs)
ReDim br(1 To UBound(ar), 1 To 3)
For i = 2 To UBound(ar)
If Trim(ar(i, 3)) <> "" Then
n = n + 1
br(n, 1) = Format(Date, "m-d")
br(n, 2) = ar(i, 1)
br(n, 3) = ar(i, 3)
End If
Next i
If n = "" Then MsgBox "数据源为空,请先录入数据!": End
With ws
r = ws.Cells(Rows.Count, "k").End(xlUp).Row + 1
.Cells(r, "k").Resize(n, UBound(br, 2)) = br
End With
If Len(ws.[f2].Value) > 0 Then
With Sheets("车票结存")
cr = .[i1].CurrentRegion
dr = Application.Index(cr, 1)
x = Application.Match(ws.[f2].Value, .Columns("i"), 0)
For i = 1 To n
y = Application.Match(br(i, 2), dr, 0)
cr(x, y) = cr(x, y) + br(i, 3)
Next
.[i1].CurrentRegion = cr
End With
End If
ws.Range("c2:c" & rs).ClearContents
ws.Range("f2").ClearContents
Application.ScreenUpdating = True '开启屏幕刷新
End Sub
2.1)关于”每班关键信息录入表“日期功能设置能否将原有的当C列非空时,配票日期(D列)能自动记录当前日期且除非手动更改D列日期,否则不再变动;2)当清空C列数据时,D列、E列同步清空;3)盘点日录入日期时(即P1-P6的合并单元格内),如结账日期大于盘点日期的均按盘点日期显示,清空盘点日期则按原规则显示。麻烦大神再帮忙看看能否实现这此功能,万分感谢! |
|