標題:
請教版主及各位高手:如何在多個群組裡新增序號並自動進位?
[打印本頁]
作者:
cmo140497
時間:
2013-5-21 09:47
標題:
請教版主及各位高手:如何在多個群組裡新增序號並自動進位?
Dear 版主及各位高手:
小弟想如何在多個群組裡新增序號並自動搜尋指定群組的最後序號,並自動進位?
這些群組會在同一B欄裡,一組有6個位元,左起第1,2位元為週別Weeknum,左起第3,4位元為群組別,左起第5,6位元則為序號,分別為0~9~A~Z,當第6位元到Z時則自動進位第5位元+1
[attach]15042[/attach]
[attach]15043[/attach]
作者:
GBKEE
時間:
2013-5-21 13:44
回復
1#
cmo140497
你可以上傳對照於,新增序號,並自動進位,的範例.
作者:
cmo140497
時間:
2013-5-21 14:13
回復
2#
GBKEE
不好意思,小弟大概寫了一段就只能根據最後一筆之資料作新增及序號之進位,後來想到因為數據中混雜很多不同群組,不同群組的起始序號均不同,
Sub FindNewSeq()
Dim lastStr$, r%, LAsc%, RAsc%, RChr$, LChr$, ThisWeekNm%
'0~9:48~57
'A~Z:65~90
With Sheets(1)
r = .Range("C65536").End(xlUp).Row
lastStr = .Cells(r, 3)
ThisWeekNm = Application.WorksheetFunction.WeekNum(Date)
If Len(lastStr) > 6 Or Len(lastStr) < 11 Then
response = MsgBox("請問是否增加子批:", 4, "提示")
If response = vbNo And Len(lastStr) = 6 Then
'無子批也不想增加子批
LAsc = Asc(Right(lastStr, 2))
RAsc = Asc(Right(lastStr, 1))
If RAsc < 57 And RAsc > 47 Then
RAsc = RAsc + 1
ElseIf RAsc = 57 Then
RAsc = RAsc + 8
ElseIf RAsc < 90 And RAsc > 65 Then
RAsc = RAsc + 1
ElseIf RAsc = 90 Then
LAsc = LAsc + 1
RAsc = 48
Else
RAsc = RAsc + 1
End If
RChr = Chr(RAsc)
LChr = Chr(LAsc)
.Cells(r + 1, 3) = ThisWeekNm & "DM" & LChr & RChr
Else
If response = vbYes And Len(lastStr) = 6 Then
'無子批欲增加子批
RAsc = Asc(Right(lastStr, 1))
LAsc = Asc(Right(lastStr, 2))
RAsc = RAsc + 1
RChr = Chr(RAsc)
LChr = Chr(LAsc)
response2 = MsgBox("是否根據上一批新增子批(Yes/No) ?", 4, "提示")
If response2 = vbNo Then
'不根據上批ID,而新增ID及子批
.Cells(r + 1, 3) = ThisWeekNm & "DM" & LChr & RChr & "B001"
ElseIf response2 = vbYes Then
'根據上批ID作新增子批
.Cells(r + 1, 3) = lastStr & "B001"
End If
ElseIf response = vbYes And Len(lastStr) = 10 Then
'有子批欲增加子批
RAsc = Asc(Right(lastStr, 1))
RAsc = RAsc + 1
RChr = Chr(RAsc)
.Cells(r + 1, 3) = Left(lastStr, 9) & RChr
Else
'有子批不想增加子批
LAsc = Asc(Right(lastStr, 6))
RAsc = Asc(Right(lastStr, 5))
If RAsc < 57 And RAsc > 47 Then
RAsc = RAsc + 1
ElseIf RAsc = 57 Then
RAsc = RAsc + 8
ElseIf RAsc < 90 And RAsc > 65 Then
RAsc = RAsc + 1
ElseIf RAsc = 90 Then
LAsc = LAsc + 1
RAsc = 48
Else
RAsc = RAsc + 1
End If
RChr = Chr(RAsc)
LChr = Chr(LAsc)
.Cells(r + 1, 3) = ThisWeekNm & "DM" & LChr & RChr
End If
End If
End If
End With
End Sub
複製代碼
[attach]15047[/attach]
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)