Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 需要将数据拆分为多列_Excel_Vba - Fatal编程技术网

Excel 需要将数据拆分为多列

Excel 需要将数据拆分为多列,excel,vba,Excel,Vba,我在一列中有数据,我想将其拆分为多列。 例如,我有如下数据 123*4546.765,4653:342.324 我想将其拆分为123列、4546列、765列、4653列等等……尝试下面的代码(使用RegEx) RegEx模式正在查找任何连续的1到10位.pattern=“[0-9]{1,10}” 然后,如果至少找到一个匹配项,则在所有匹配项中循环并输出它们(从单元格“A1”并向右移动一列) 代码 Option Explicit Sub ExtractNumbers() Dim Col As

我在一列中有数据,我想将其拆分为多列。 例如,我有如下数据

123*4546.765,4653:342.324
我想将其拆分为
123
列、
4546
列、
765
列、
4653
列等等……

尝试下面的代码(使用
RegEx

RegEx
模式正在查找任何连续的1到10位
.pattern=“[0-9]{1,10}”

然后,如果至少找到一个匹配项,则在所有匹配项中循环并输出它们(从单元格“A1”并向右移动一列)

代码

Option Explicit

Sub ExtractNumbers()

Dim Col As Long
Dim Reg1 As Object
Dim RegMatches As Variant
Dim Match As Variant

Set Reg1 = CreateObject("VBScript.RegExp")
With Reg1
    .Global = True
    .IgnoreCase = True
    .Pattern = "[0-9]{1,10}" ' Match any set of 9 digits
End With

Set RegMatches = Reg1.Execute("123*4546.765,4653:342.324") '<-- you can use a `Range` value instead of hard-code 

If RegMatches.Count >= 1 Then '<-- check that at least 1 match made with the RegEx
    Col = 1
    For Each Match In RegMatches
        MsgBox Match ' <-- output in msgbox
        Cells(1, Col).Value = Match '<-- output the numbers from Cell A1 and move one column to the right
        Col = Col + 1
    Next Match
End If

End Sub
选项显式
子编号()
暗色如长
Dim Reg1作为对象
Dim RegMatches作为变量
作为变体的暗淡匹配
Set Reg1=CreateObject(“VBScript.RegExp”)
使用Reg1
.Global=True
.IgnoreCase=True
.Pattern=“[0-9]{1,10}”匹配任何一组9位数字
以

设置RegMatches=Reg1.Execute(“123*4546.7654653:342.324”)=1,然后“您认为如何实现或如何实现它。”。我想您必须使用Range.TextToColumns方法。制表符、逗号、分号和每次传递的另一个字符。VBA中的一项非常重要的任务,您可以从录制一些宏开始,然后在IDE中对它们进行优化。当你有一些实质性的代码不能正常工作时,就发布一个问题。