[英]Concatenate alternating fixed column headers and row values
以下UDF可以做到:
Function unionText(ttl As Range, rng As Range) As String
Dim i As Long
If ttl.Cells.Count <> rng.Cells.Count Or _
ttl.Rows.Count <> 1 Or rng.Rows.Count <> 1 Then
unionText = CVErr(xlErrValue)
Exit Function
End If
For i = 1 To ttl.Cells.Count
unionText = unionText & ttl(i) & "=" & rng(i) & ";"
Next i
End Function
在工作表中這樣稱呼它:
=unionText(before!$A$1:$C$1,before!A2:C2)
然后抄下來
我的顯然在同一張紙上,但是上面的公式使用的是您的紙頁參考。
您可以臨時使用此宏代碼,並假設只有一行值:
Sub Macro1()
' Macro1 Macro
Range("A1").Select
Dim r As Byte
Dim c as Byte
Dim stringunion As String
r = 1
c = 1
Do While Cells(r, c) <> ""
stringunion = stringunion & Cells(r, c).Value & "=" & Cells(r + 1, c) & ";"
c = c + 1
Loop
MsgBox stringunion
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.