gpt4 book ai didi

vba - 添加前导 '0' 进行格式化直至 5 位数字值

转载 作者:行者123 更新时间:2023-12-02 23:34:31 25 4
gpt4 key购买 nike

目前,我成功开发了一种字母数字类型的 ID。但是我尝试运行几次,发现有时数值只会显示 4 位数字(假设没有输入 1 个 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

最佳答案

更改这行代码

alphanumeric = alpha & numeric

进入

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

关于vba - 添加前导 '0' 进行格式化直至 5 位数字值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44063072/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com