2017-10-06 43 views
0

我在A列中的村莊 - 城堡,J列中的各個地區名稱屬於村莊。我想將所有以逗號分隔的vilalge-urls轉換爲列R execpt列A中的值。轉置應根據比較值J(Dist)完成。基於參考值轉置數據,然後從輸出中減去文本

So every R2=R2-A2 

宏應該適用於所有工作表。

輸入:

柱A值:

URL 
<a href="https://D.COM/Campbelbay" >Campbelbay</a>, 
<a href="https://D.COM/Carnicobar" >Carnicobar</a>, 
<a href="https://D.COM/Champin" >Champin</a>, 
<a href="https://D.COM/Aerial-Bay" >Aerial Bay</a>, 
<a href="https://D.COM/Bakultala" >Bakultala</a>, 
<a href="https://D.COM/Betapur" >Betapur</a>, 
<a href="https://D.COM/Diglipur" >Diglipur</a>, 
<a href="https://D.COM/Aberdeen-Bazar" >Aberdeen Bazar</a>, 
<a href="https://D.COM/Bambooflat" >Bambooflat</a>, 
<a href="https://D.COM/Beachdera" >Beachdera</a>, 
<a href="https://D.COM/Beodnabad" >Beodnabad</a>, 

J列值:

DISTRICT 
Nicobar 
Nicobar 
Nicobar 
North And Middle Andaman 
North And Middle Andaman 

輸出:

MERGEDURL 
    <a href="https://D.COM/Carnicobar" >Carnicobar</a>,<a href="https://D.COM/Champin" >Champin</a>,<a href="https://D.COM/Aerial-Bay" >Aerial Bay</a>,<a href="https://D.COM/Bakultala" >Bakultala</a> 
<a href="https://D.COM/Campbelbay" >Campbelbay</a>,<a href="https://D.COM/Champin" >Champin</a>,<a href="https://D.COM/Aerial-Bay" >Aerial Bay</a>,<a href="https://D.COM/Bakultala" >Bakultala</a> 
<a href="https://D.COM/Campbelbay" >Campbelbay</a>,<a href="https://D.COM/Carnicobar" >Carnicobar</a>,<a href="https://D.COM/Aerial-Bay" >Aerial Bay</a>,<a href="https://D.COM/Bakultala" >Bakultala</a> 
<a href="https://D.COM/Campbelbay" >Campbelbay</a>,<a href="https://D.COM/Carnicobar" >Carnicobar</a>,<a href="https://D.COM/Champin" >Champin</a>,<a href="https://D.COM/Bakultala" >Bakultala</a> 
<a href="https://D.COM/Campbelbay" >Campbelbay</a>,<a href="https://D.COM/Carnicobar" >Carnicobar</a>,<a href="https://D.COM/Champin" >Champin</a>,<a href="https://D.COM/Aerial-Bay" >Aerial Bay</a> 

宏用於合併:

Sub Transpose() 
Dim w As Excel.Worksheet 
Dim r As Excel.Range 

For Each w In ThisWorkbook.Worksheets 
    Set r = w.Range("a2", w.Range("a1").End(xlDown)) 
    w.Range("q1").Value = Join(Application.Transpose(r), ",") 
Next w 

末次

感謝您的時間。

信貸和Refrence宏:VBA Provided by Imran Malek

Substitute Text macro provided here by Lee

回答

0

我不知道我理解你的問題。

Sub trans() 
    Dim vDB, vData, vR(), vResult() 
    Dim s As String, s2 As String 
    Dim Ws As Worksheet 
    Dim i As Long, n As Long 
    For Each Ws In Worksheets 
     With Ws 
      vDB = .Range("a1", .Range("a" & Rows.Count).End(xlUp)) 
      n = UBound(vDB, 1) 
      ReDim vR(1 To n): ReDim vResult(1 To n, 1 To 1) 
      For i = 1 To n 
       vR(i) = vDB(i, 1) 
      Next i 
      For i = 1 To n 
       s = vR(i) 
       vR(i) = Empty 
       s2 = Join(vR, "") 
       Mid(s2, Len(s2), 1) = Space(1) 
       vResult(i, 1) = Trim(s2) 
       vR(i) = s 
      Next i 
      .Range("r1").Resize(n) = vResult 
     End With 
    Next Ws 
End Sub 
+0

謝謝李,再次你在我的幫助。我想根據列J中的對應值將列A值合併並添加到列R.因此,J中的值發生變化,然後合併列A中的相應值開始新跳過列A中的相應單元格值,並將結果添加到列R. – Ram

相關問題