|
你的表格添加过列数据了,所以列号要修改,备注备份只复制单元格数据,要备份图片还要改代码。
- Sub 数据保存()
- With Sheets("单据")
- ar = Range(.[a1], .Cells(Rows.Count, 1).End(3).Offset(0, 13))
- ReDim arr(1 To UBound(ar), 1 To UBound(ar, 2) + 3)
- 单号 = .[N2] & Format(Val(.[O2]), "000000")
- 客户 = .[b5]
- 开单时间 = .[N5]
- For i = 7 To UBound(ar)
- If ar(i, 1) = "合计" Then Exit For
- If ar(i, 10) <> 0 Or ar(i, 11) <> 0 Then '金额或总平方数不为0算一条记录
- n = n + 1
- arr(n, 1) = 客户
- arr(n, 2) = 单号
- arr(n, 3) = 开单时间
- For j = 1 To UBound(ar, 2)
- arr(n, j + 3) = ar(i, j)
- Next j
- End If
- Next i
- End With
- If n > 0 Then
- With Sheets("单据数据")
- .Cells(Rows.Count, 1).End(3).Offset(1, 0).Resize(n, UBound(arr, 2)) = arr
- [O2] = [O2] + 1
- MsgBox "本单据打印并保存完毕!"
- End With
-
- ' Dim rng As Range
- ' With Sheets("单据数据")
- ' Set rng = .Columns("A:A").Find(what:=单号)
- ' If Not rng Is Nothing Then
- ' MsgBox "本单据已经保存过!本次仅打印"
- ' Else
- ' .Cells(Rows.Count, 1).End(3).Offset(1, 0).Resize(n, UBound(arr, 2)) = arr
- ' [l2] = [l2] + 1
- ' MsgBox "本单据打印并保存完毕!"
- ' End If
- ' End With
- Else
- MsgBox "本表没有实际数据,请核对!"
- End If
- End Sub
复制代码 |
|