字符串的标准模式为16-000q.使用前导零从q创建4位数字的字符串 [英] Standard pattern of string is like 16-000q. Use leading zeros to create 4 digit string from q

查看:38
本文介绍了字符串的标准模式为16-000q.使用前导零从q创建4位数字的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我正在使用

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

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

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.

推荐答案

尝试使用 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"

Format 的文档: https://msdn.microsoft.com/en-us/library/office/gg251755.aspx

这篇关于字符串的标准模式为16-000q.使用前导零从q创建4位数字的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆