打印到单元格时如何保留string中的尾随空格?

当我试图打印出尾随空格的string时,尾随空格会被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 

设置文本格式以防止自动转换:

 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 
 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