首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >需要将数据拆分为多列

需要将数据拆分为多列
EN

Stack Overflow用户
提问于 2017-02-17 16:55:13
回答 1查看 448关注 0票数 0

我在一列中有数据,我想将其拆分成多列。例如,我有像这样的数据

代码语言:javascript
复制
123*4546.765,4653:342.324

我想将其拆分为列中的123、列中的4546、列中的765、列中的4653,依此类推……

EN

回答 1

Stack Overflow用户

发布于 2017-02-17 17:15:55

尝试下面的代码(使用RegEx)。

RegEx模式查找任意连续的1到10位数字.Pattern = "[0-9]{1,10}"

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

代码

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42293438

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档