|
本帖最后由 qmlyc1 于 2018-9-17 21:33 编辑
以下是以年月日+序号的编码,请帮忙改成年月+序号,谢谢!Private Function 生成编号() As String On Error Resume Next '
Dim theYear$, theMonth$, theDay$
Dim theCell As Range, theFirstAddress$, theStrMaxNumNow$, theStrNum$
theYear = Year(Date): theMonth = Format(Month(Date), "00"): theDay = Format(Day(Date), "00")
theStrNum = "GS" & theYear & theMonth & theDay
theStrMaxNumNow = "00"
With ThisWorkbook.Worksheets("汇总表").Columns(3)
Set theCell = .Cells.Find(what:=theStrNum, after:=.Cells(.Count), LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, MatchByte:=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
生成编号 = "GS" & theYear & theMonth & theDay & Format(CVar(theStrMaxNumNow) + 1, "00")
End Function
|
|