|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 925977828 于 2018-6-17 13:17 编辑
点击出库单的“新单”按钮后出库单内容清空出库单编号自动+1 出库单的格式是固定码“SC”+年份“2018”(根据系统时间变化)+月份"06"(根据系统时间变化)+流水号0000开始(流水号每次点击“新单”自动+1,),列如:SC2018060001,SC2018060002.......SC2018070020,SC2018070021......SC2019010001(月份变化流水号还是累加,不根据月份变化从新排号,跨年以后流水号又从0001开始)。
现在这个代码,累加到0002,后面就不+1了。望哪位师傅帮忙修改下,谢谢
以下是代码1
Private Sub CommandButton2_Click() '新单
On Error Resume Next '
Dim r%, i%
Application.ScreenUpdating = False
Set rg = Sheets("汇总表").[c65536].End(3)
[i3] = 生成编号
代码2
Private Function 生成编号() As String
On Error Resume Next '
Dim theYear$, theMonth$
Dim theCell As Range, theFirstAddress$, theStrMaxNumNow$, theStrNum$
theYear = Year(Date): theMonth = Format(Month(Date), "00"):
theStrNum = "SC" & theYear & theMonth
theStrMaxNumNow = "0000"
With ThisWorkbook.Worksheets("汇总表").Columns(3)
Set theCell = .Cells.Find(what:=theStrNum, after:=.Cells(.Count), LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False)
If Not theCell Is Nothing Then
theFirstAddress = theCell.Address
Do
If Right(theCell, 3) > theStrMaxNumNow Then theStrMaxNumNow = Right(theCell, 2)
Set theCell = .FindNext(theCell)
Loop Until theCell.Address = theFirstAddress
End If
End With
生成编号 = "SC" & theYear & theMonth & Format(CVar(theStrMaxNumNow) + 1, "0000")
End Function
|
|