Standard pattern of string is like 16-000q. Use le

2019-09-06 02:12发布

Currently, i am using

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

to generate my code. But I realise that when q becomes a 2 digit int (i.e 11), the output is like 16-00011, which I don't want. I want the output to be like 16-0011.

1条回答
手持菜刀,她持情操
2楼-- · 2019-09-06 03:01

Try this using Format:

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"

Documentation for Format: https://msdn.microsoft.com/en-us/library/office/gg251755.aspx

查看更多
登录 后发表回答