添加前导'0'格式,直到5位数字的值

目前我设法开发了一个字母数字types的ID。 但我试了几次,发现有时数值只会显示4位数字(假设一个0没有input),所以我缺乏这一个代码,以帮助我做到5位数字,任何一个头脑给我那个黄金代码? 谢谢

这是我目前的代码

Private Sub Workbook_Open() ' Called every time you open the Excel document Dim alpha As String Dim numeric As Long Dim alphanumeric As String Randomize numeric = CLng(Rnd() * 99999) ' CLng converts the floating point number to a long integer alpha = "SCC" alphanumeric = alpha & numeric Dim rowNum As Integer Dim colNum As Integer rowNum = 6 colNum = 4 With ThisWorkbook.Sheets("Sheet1").Cells(rowNum, colNum) If (.Value = "") Then .Value = alphanumeric End If End With End Sub 

更改这一行代码

 alphanumeric = alpha & numeric 

 alphanumeric = alpha & Format(numeric,"0000") '<~or into any number of zeros you prefer 

更换

 alphanumeric = alpha & numeric 

 alphanumeric = alpha & Format(numeric, "00000") 

这将始终返回一个5位数字