You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Excel VBA批量生成客户发票求助:需按客户汇总订单而非单商品

按客户汇总生成发票的Excel VBA问题及解决

我开发了一款Excel VBA工具,用于给童装直播销售的客户批量生成发票。所有订单都记录在Excel工作表中,需求是将订单按客户分类,为每位客户生成对应的汇总发票。

我原本使用的代码如下:

Sub Create_PDF_Files()

Application.DisplayAlerts = False
Application.ScreenUpdating = False

Dim dsh As Worksheet
Dim tsh As Worksheet
Dim setting_Sh As Worksheet

Set dsh = ThisWorkbook.Sheets("uzsakymai")
Set tsh = ThisWorkbook.Sheets("lapukas")
Set setting_Sh = ThisWorkbook.Sheets("Settings")


Application.DisplayStatusBar = True
Application.StatusBar = ""

Dim i As Integer
Dim File_Name As String

For i = 2 To dsh.Range("A" & Application.Rows.Count).End(xlUp).Row

Application.StatusBar = i - 1 & "/" & dsh.Range("A" & Application.Rows.Count).End(xlUp).Row - 1

tsh.Range("D1").Value = dsh.Range("C" & i).Value
tsh.Range("A4").Value = dsh.Range("B" & i).Value
tsh.Range("B4").Value = dsh.Range("A" & i).Value & " - " & dsh.Range("E" & i).Value
tsh.Range("P4").Value = dsh.Range("D" & i).Value

File_Name = dsh.Range("A" & i).Value & "(" & dsh.Range("C" & i).Value & "-" & dsh.Range("D" & i).Value & ").pdf"
tsh.ExportAsFixedFormat xlTypePDF, setting_Sh.Range("F4").Value & "\" & File_Name

Next i

Application.StatusBar = ""

MsgBox "Done"
End Sub

初始问题

当前代码会为每个商品单独生成发票,无法实现按客户汇总生成的需求。


优化进展与新问题

采用ALeXceL提供的代码修改后,已经能按客户汇总生成发票,但出现新问题:发票里第一个商品显示正常,其余商品的内容从A24单元格开始错位显示。


最终结果

问题已解决!


内容的提问来源于stack exchange,提问作者Arnelis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 16:36:07