2017-11-22 4 views
1

後ろに空白がある文字列を出力しようとすると、末尾のスペースがExcelによって自動的に切り捨てられます。私はそれらを保存したい。文字列内の末尾のスペースをセルに印刷する際に、この文字列を保持する方法はありますか?

サンプル:

自動変換を防ぐために、テキスト形式に設定し
Sub stringspace() 

stringg = "23 " 
MsgBox Len(stringg) 'here it is 3 
Cells(1, 1) = stringg 
MsgBox Len(Cells(1, 1)) 'here it is 2 

End Sub 

答えて

1

Sub stringspace() 

    stringg = "23 " 
    MsgBox Len(stringg) 'here it is 3 
    Cells(1, 1).NumberFormat = "@" 
    Cells(1, 1) = stringg 
    MsgBox Len(Cells(1, 1)) 'here it is 3 

End Sub 
+0

をありがとう!それはうまくいった。 – Surya

0
Sub StringSpace_Modified() 

    Cells(2, 1) = "'23 " ' Use a single quote at the beginning 
    Debug.Print Len(Cells(2, 1)) ' Displays 3 in immediate window 

End Sub 
関連する問題