VBA excel粘贴为文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45477870/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA excel paste as text
提问by HammerUser
I need to paste numbers as text. It is problematic due to lots of zeros in front (but I need them there). First snippet, does not work (I found it on the internet).
我需要将数字粘贴为文本。由于前面有很多零,这是有问题的(但我在那里需要它们)。第一个片段,不起作用(我在互联网上找到了它)。
Worksheets("B").Range("k7:k7").PasteSpecial Format:=”Text”,
Link:=False, DisplayAsIcon:=False
The other I recorded, but it not always work.
我录制的另一个,但它并不总是有效。
PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False
Could someone suggest me a better solution, please?
有人可以建议我更好的解决方案吗?
采纳答案by mdialogo
You need to format the cells/column to 'Text' format then paste the numbers to preserve the leading zeros. If it still doesn't work, try to paste the numbers to Notepad first and then copy all numbers in Notepad and paste it back to the cells/column now formatted as 'Text'. Hope it helps.
您需要将单元格/列的格式设置为“文本”格式,然后粘贴数字以保留前导零。如果它仍然不起作用,请尝试先将数字粘贴到记事本,然后复制记事本中的所有数字并将其粘贴回现在格式化为“文本”的单元格/列。希望能帮助到你。
回答by Arun Raj
If you are trying to copy paste a single cell, instead of copy pasting get the value from the cell append single quote and store the value in the destination
如果您尝试复制粘贴单个单元格,而不是复制粘贴从单元格中获取值附加单引号并将值存储在目标中
回答by Prebsus
I'm having trouble recreating your issue.
我无法重现您的问题。
I created a new sheet with with the following:
The following code seems to do what you wish:
以下代码似乎可以满足您的需求:
Sub pasteAsText()
ActiveSheet.Range("A2").Copy
ActiveSheet.Range("C2").PasteSpecial
ActiveSheet.Range("A3").Copy
ActiveSheet.Range("C3").PasteSpecial
ActiveSheet.Range("A4").Copy
ActiveSheet.Range("C4").PasteSpecial
End Sub
Does that solve your problem?
这能解决你的问题吗?