在Excel中创build字母数字序列

通过使用excel,我需要创build从0000到ZZZZ的4个字母/数字的字母数字序列。 我创build了一个如下所示的macros:

Sub a() Dim iChar1 As Integer, iChar2 As Integer, iChar3 As Integer, iChar4 As Integer Dim sOutput As String For iChar1 = 65 To 90 For iChar2 = 65 To 90 For iChar3 = 65 To 90 For iChar4 = 65 To 90 sOutput = Chr(iChar1) & Chr(iChar2) & Chr(iChar3) & iChar4 ActiveCell.Value = sOutput ActiveCell.Offset(1, 0).Activate Next: Next: Next: Next End Sub 

问题是用这种方法我只能得到alpha序列,因为从65到90的ASCII字典是相反的,我还需要数字值(从48到57的ASCII)。 怎么做? 或者,你知道另一种方法吗?

也许就像这样,使用input数组和输出数组而不是逐个单元地写入

 Sub a() Dim vChars Dim iChar1 As Integer, iChar2 As Integer, iChar3 As Integer, iChar4 As Integer Dim sOut(1 To 839808, 1 To 2) As String Dim lCounter As Long Dim lCol As Long vChars = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", _ "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z") lCounter = 1 lCol = 1 For iChar1 = 0 To 35 For iChar2 = 0 To 35 For iChar3 = 0 To 35 For iChar4 = 0 To 35 sOut(lCounter, lCol) = vChars(iChar1) & vChars(iChar2) & vChars(iChar3) & vChars(iChar4) If lCounter = 839808 Then lCol = 2 lCounter = 1 Else lCounter = lCounter + 1 End If Next iChar4 Next iChar3 Next iChar2 Next iChar1 Range("A1").Resize(839808, 2).Value = sOut End Sub