2017-02-17 2 views
0

하나의 열에 데이터가 있고 여러 열로 나누고 싶습니다. 예를 들어 나는 ...데이터를 여러 열로 분할해야합니다.

123*4546.765,4653:342.324 

같은 데이터가 나는 열에 123 같은 열에서 열에서 열에서 4546, 765, 4653 등을이 분할 할

+0

. 나는 당신이 Range.TextToColumns 메서드를 사용해야 할 것 같아요. 탭, 쉼표, 세미콜론 및 ** 패스 당 한 ** 다른 문자. VBA의 중요하지 않은 작업이므로 일부 매크로를 기록한 다음 IDE에서 수정하면됩니다. 상당한 코드를 가지고있을 때는 질문을 게시하십시오. –

답변

0

시도가 아래 코드 (RegEx 사용)

RegEx 패턴은 연속적인 1에서 10까지의 숫자 .Pattern = "[0-9]{1,10}"을 찾습니다.

최소 1 개의 일치 항목이 발견되면 모든 일치 항목 내부를 반복하여 출력 (셀 "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 
관련 문제