2017-01-16 2 views
0

から4桁の文字列を作成するために、先行ゼロを使用して、私は私のコードを生成する文字列の標準パターンは16-000qのようです。現在、Q

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

を使用しています。しかし、qが2桁の整数(つまり11)になると、出力は16-00011のようになりますが、これは嫌です。私は出力を16-0011のようにしたい。

答えて

0

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

関連する問題