Vba 字符串的标准模式类似于16-000q。使用前导零从q创建4位字符串

Vba 字符串的标准模式类似于16-000q。使用前导零从q创建4位字符串,vba,excel,Vba,Excel,目前,我正在使用 Cells(i, 6) & ("-000") & (q) 生成我的代码。但是我意识到当q变成2位整数(即11)时,输出就像16-00011,这是我不想要的。我希望输出类似于16-0011 尝试使用格式: Dim myOutput as String myOutput = Cells(i, 6) & "-" & Format(q, "0000") ' If Cells(i, 6) = 16, and q = 11 then ' >>

目前,我正在使用

Cells(i, 6) & ("-000") & (q) 

生成我的代码。但是我意识到当
q
变成2位整数(即
11
)时,输出就像
16-00011
,这是我不想要的。我希望输出类似于
16-0011

尝试使用
格式

Dim myOutput as String
myOutput = Cells(i, 6) & "-" & Format(q, "0000")

' If Cells(i, 6) = 16, and q = 11 then
' >> myOutput = "16-0011"

' If Cells(i, 6) = 16, and q = 9 then
' >> myOutput = "16-0009"
格式的文档