|
- '===============清空开票生成编号
- Private Sub CommandButton1_Click()
- Dim n1&, n2&, no&, i&, w$
- Range("b6,b7,b8,a10:j12") = ""
- With Sheets("流水记录")
- i = .Range("a65536").End(3).Row
- n1 = Month(Date)
- n2 = Month(.Range("b" & i))
- If n1 > n2 Or i = 1 Then
- no = 1
- Else
- no = Right(.Range("a" & i), 3) + 1
- End If
- w = Year(Date) & Format(Month(Date), "00") & Format(Day(Date), "00") & Format(no, "000")
- End With
- Range("j5") = w
- Range("j7") = Format(Date, "yyyy年mm月dd日")
- End Sub
- '=================保存到数据库
- Private Sub CommandButton2_Click()
- Dim arr, brr(), n&, i&, r&, j&, k&
- n = Application.CountA(Range("a10:a11"))
- arr = Range("a10:i" & 9 + n)
- With Sheets("流水记录")
- k = .Range("a65536").End(3).Row
- i = k + 1
- Set c = .Range("a:a").Find(Range("j5"), , , , , 1)
- If Not c Is Nothing Then
- MsgBox "该收据已存在不能重复保存。"
- Exit Sub
- End If
- If Range("b6") = "" Or Range("b7") = "" Then
- MsgBox "发货单位、客户名称不能为空。"
- Exit Sub
- End If
- If Range("a10") = "" Or Range("f10") = "" Or Range("g10") = "" Or Range("h10") = "" Then
- MsgBox "数据填写不完整。"
- Exit Sub
- End If
- ReDim brr(1 To n, 1 To 11)
- For r = 1 To UBound(arr)
- j = j + 1
- brr(j, 1) = Range("j5")
- brr(j, 2) = Format(Range("j7"), "yyyy-mm-dd")
- brr(j, 3) = Range("b6")
- brr(j, 4) = Range("b7")
- brr(j, 5) = Range("b8")
- brr(j, 6) = arr(r, 1)
- brr(j, 7) = arr(r, 3)
- brr(j, 8) = arr(r, 4)
- brr(j, 9) = arr(r, 5)
- brr(j, 10) = arr(r, 6)
- brr(j, 11) = arr(r, 9)
- Next
- k = .Cells(65536, 1).End(3).Row + 1
- .Cells(k, 1).Resize(j, 11) = brr
- End With
- MsgBox "OK!保存成功!"
- End Sub
复制代码 |
|