|
- Sub AddDataAndPrint()
- Dim wsReceipt As Worksheet
- Dim wsDetail As Worksheet
- Dim lastRow As Long
- Dim lastRowDetail As Long
- Dim teamName As String
- Dim i As Integer
-
- ' 设置工作表
- Set wsReceipt = ThisWorkbook.Sheets("收据")
-
- ' 找到“收据”表中的最后一行数据
- lastRow = wsReceipt.Cells(wsReceipt.Rows.Count, "A").End(xlUp).Row
-
- ' 读取客户名称(车队名称)
- teamName = wsReceipt.Range("B3").Value
-
- ' 根据车队名称选择详细工作表
- Select Case teamName
- Case "信而达"
- Set wsDetail = ThisWorkbook.Sheets("信而达明细 ")
- Case "吉顺隆"
- Set wsDetail = ThisWorkbook.Sheets("吉顺隆明细")
- Case "邦达"
- Set wsDetail = ThisWorkbook.Sheets("邦达明细 ")
- Case "灵鹤"
- Set wsDetail = ThisWorkbook.Sheets("灵鹤明细")
- Case "得盛"
- Set wsDetail = ThisWorkbook.Sheets("得盛明细")
- ' 添加更多选项,如果有更多车队
- Case Else
- MsgBox "未找到对应的车队明细表。"
- Exit Sub
- End Select
-
- ' 在详细工作表的末尾添加一行数据
- lastRowDetail = wsDetail.Cells(wsDetail.Rows.Count, "A").End(xlUp).Row + 1
- For i = 1 To 11 ' 根据详细表的列数调整
- wsDetail.Cells(lastRowDetail, i).Value = wsReceipt.Cells(4, i).Value ' 调整行和列索引
- Next i
-
- ' 更新账户余额
- wsDetail.Cells(lastRowDetail, 10).Formula = "=D" & lastRowDetail & "-H" & lastRowDetail
-
- ' 打印收据工作表
- wsReceipt.PrintOut
- End Sub
复制代码 |
|