根據參考值轉置數據,然后從輸出中減去文本

[英]Transpose data based on reference value then substract text from output


I have the village-urls in column A, in column J respective district name the village belongs to. I want to tanspose all the vilalge-urls separated by comma to column R execpt the value in column A. Transpose should done based on comparitive value J(Dist).

我在A欄中有村庄網址,在J列中,村庄所屬的區域名稱。我想將所有用逗號分隔的vilalge-urls替換為R列,然后執行A列中的值。轉置應根據比較值J(Dist)完成。

So every R2=R2-A2

Macro should work for all worksheets.

宏應適用於所有工作表。

Input:

輸入:

Column A Values:

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>,

Column J Values:

J列值:

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

Output:

輸出:

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>

Macro Used to Merge :

用於合並的宏:

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

End Sub

結束子

Thanks for your time.

謝謝你的時間。

Credit and Refrence Macros:VBA Provided by Imran Malek:

Credit和Refrence Macros:VBA由Imran Malek提供:

Substitute Text macro provided here by Lee

Lee提供的替換文字宏

1 个解决方案

#1


0  

I'm not sure I understood your problem.

我不確定我理解你的問題。

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

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2017/10/06/72f1050cb988dce9eee44dc76e3ca0d7.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com