2016-04-22 10 views
-1

2つの列A & B列の順番に追加する必要があります。列Aの最初のセル、列Bの最初のセル、列Aの次の列セル列B第二細胞続い1つの列に2列のデータを入力するシーケンス

カラム ジョーンズ 1234FG thepark

列B JONESアンドロイド ジョーンズJONES アンドロイドANDROID 1234FG 1234SS thepark PARK

は親切に指定された結果を得るために、任意の式またはVBAコードを助言210 ANDROID 1234SS PARK

結果。

+0

こんにちはSrinathは、SOへようこそ下記のコードを参照してください。ここの人々はあなたのコードを無料で書くためのものではありません。連結する 'vba'文字列演算子は'& 'です。 –

+0

結果が1つのセルまたは対応する行のセルに存在する必要がありますか(C1のJones Jones、C2のandroid ANDROIDなど)? – Brian

答えて

0

Sub test() 
    Dim i As Long, j As Long 
    Dim output As String 
    Dim text1 As String 
    Dim text2 As String 
    Dim text1split1 
    Dim text1split2 
    Dim lastrow As Long 
    lastrow = Range("A" & Rows.Count).End(xlUp).Row 
    For i = 1 To lastrow 
     text1 = Range("A" & i).Value 
     text2 = Range("B" & i).Value 
     text1split1 = Split(text1, " ") 
     text1split2 = Split(text2, " ") 
     For j = 0 To UBound(text1split1) 
      If output <> "" Then 
       output = output & " " & text1split1(j) & " " & text1split2(j) 
      Else 
       output = text1split1(j) & " " & text1split2(j) 
      End If 
     Next j 
     Range("C" & i).Value = output 
    Next i 
End Sub 
関連する問題