ZQ7*_*ZQ7 2 excel vba excel-vba
目前我设法开发了一种字母数字ID.但我尝试运行几次,发现有时数字值只会显示4位数(假设没有输入一个0)所以我缺少一个代码来帮助我使它达到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
Run Code Online (Sandbox Code Playgroud)
更改此行代码
alphanumeric = alpha & numeric
Run Code Online (Sandbox Code Playgroud)
成
alphanumeric = alpha & Format(numeric,"0000") '<~or into any number of zeros you prefer
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
483 次 |
| 最近记录: |