我有一列需要分成多列,宏可以正常工作。其中一列有大量数字,在使用 texttocolumns 时它们需要是文本,以防止数字四舍五入。根据文档text
我只需在 fieldInfo 中指定这一点,但它不起作用。例如,当我将第四列设置为文本时。无论我在数组中确定什么数字,该函数都只会生成第一个文本。任何围绕此问题的工作或任何需要记住的事情。当给filedinfo一个指定所有列格式的数组时,它可以工作,但我不能使用这个解决方案,因为我需要一些列不是通用格式并保留默认类型,如日期或数字。
Sub Macro1()
'
' Macro1 Macro
'
'
Range("A1:A2").Select
Range("A2").Activate
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(4, 1)), TrailingMinusNumbers:= _
True
MsgBox "here"
End Sub
数据示例
tip, 122098344989494940 , UyS, 11/12/2023
ip, 12209834498903840943494940 , UTS, 11/12/2024
Array(Array(4, 1))
表示第 4 列被解析为 General
。Sub Macro1()
Range("A1:A2").TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 2), Array(3, 1), Array(4, 2)), TrailingMinusNumbers:= _
True
MsgBox "here"
End Sub