1

好的,这是我拥有的编号系统的风格

A0
A1
A2
A3
A4
A5
A6
A7
A8
A9
AA
AB
AC
AD
....
B0
B1
B2
B3
B4
B5
B6
B7
B8
B9
BA
BB
BC
....
C0
C1
etc

我需要一个可以传入C9并返回CA的函数

澄清一下,规则是这样的

A0-> A9 然后 AA -> AZ B0 -> B9 BA -> BZ

所以第二个字母遵循这个顺序

0 1 2 3 4 5 6 7 8 9 ABCDEFGHIJKLMNOPQRSTU VWXYZ

之后,第一个数字使用相同的顺序增加

4

1 回答 1

2

这是你正在尝试的吗?逻辑是获取ASC数字并将其加一(条件适用)

Sub sample()
    Dim sCheck As String

    '~~> Uncomment any of the below to test
    'sCheck = "AZ"
    'sCheck = "B9"
    'sCheck = "ZZ"
    'sCheck = "C9"

    Debug.Print GetNext(sCheck)
End Sub

Function GetNext(s As String) As String
    If s = "" Then Exit Function

    Dim s1 As String, s2 As String

    s1 = Left(s, 1)
    s2 = Right(s, 1)

    Select Case UCase(s2)

    Case "Z"
        If s1 = "Z" Then
            GetNext = "You have reached the end of the sequence"
            Exit Function
        End If

        s1 = Chr(Asc(s1) + 1)
        s2 = "0"
    Case "9"
        s2 = "A"
    Case Else
        s2 = Chr(Asc(s2) + 1)
    End Select

    GetNext = s1 & s2
End Function
于 2013-09-16T10:05:11.213 回答