希望我能正確解釋這一點。
希望將多個作業表中的文本字串單元格組合到一個主作業表中。
基本上是 3-D 參考。但格式化為行和列。并參考一系列作業表,以便可以在書擋之間添加或洗掉新的作業表。
期望的輸出:
| 第 1 列 | 第 2 欄 | 第 3 欄 |
|---|---|---|
| WS01 單元格 B1 | WS02 單元格 B1 | WS03 單元格 B1 |
| WS01 單元格 B2 | WS02 單元格 B2 | WS03 單元格 B2 |
| WS01 單元格 B3 | WS02 單元格 B3 | WS03 單元格 B3 |
輸入:來自 B1:B3 的字串(應該成為為每個鏈接的作業表分隔成列的匹配行)
每個作業表('Worksheet 01:Worksheet 03')都遵循相同的格式:
| B欄 |
|---|
| WS## 單元格 B1 |
| WS## 單元格 B2 |
| WS## 單元格 B3 |
嘗試:
=CONCAT('作業表 01:作業表 03'!B1:B3)
結果:
WS01 單元 B1WS01 單元 B2WS01 單元 B3WS02 單元 B1WS02 單元 B2WS02 單元 B3WS03 單元 B1WS03 單元 B2WS03 單元 B3
請讓我知道你的想法。感謝您的時間。
uj5u.com熱心網友回復:
=LET(
c,CONCAT(Sheet1:Sheet4!B1:B3),
q,SEQUENCE(LEN(c)/36,3,,12),
TRANSPOSE(MID(c,q,12)))
c使用您的 CONCAT 公式來檢索所有值的串聯。
q計算序列的長度c除以每個作業表的 3 個值的文本長度(3* 長度 12 = 36)除以 3,步長為每個值的長度(12)。此序列用于MID函式中,需要轉置結果以滿足您的要求:

如果要添加作業表,則更改作業表名稱c將更改結果以顯示該作業表中的值。無需進一步調整公式。
如果將來每張紙的輸出數量或字串長度可能會發生變化,您也可以將它們定義為變數:
=LET(c,CONCAT('Worksheet 01:Worksheet 03'!B1:B3),
stringlength,12,
stringcount,3,
q,SEQUENCE(LEN(c)/(stringlength*stringcount),stringcount,,stringlength),
TRANSPOSE(MID(c,q,stringlength)))
uj5u.com熱心網友回復:
@Pb 剛剛發布了一個公式方法,但作為替代方案,這里有一個 VBA 用戶定義的公式,它回傳一個陣列。唯一棘手的部分是在 UDF 中獲取 3D 參考,因為在 VBA 中沒有等效的結構或型別:如果您嘗試直接從引數中獲取它,則會收到錯誤訊息。
構建自:https ://www.excelforum.com/excel-programming-vba-macros/476283-user-defined-function-receiving-a-range-as-parameter.html
Function MyUDF(v)
Dim c As Range, f, arr, arrWs, rngAddr
Dim arrout, indx1, indx2, i As Long, r As Long, data
On Error Resume Next
Set c = Application.Caller
On Error GoTo 0
If c Is Nothing Then
f = "=myudf(Sheet1:Sheet3!A1:A3)" 'for testing purposes (adjust as needed)...
Else
f = c.Formula 'read the formula from the calling cells
End If
f = Mid(f, 8, Len(f) - 8) 'parse out the parens and formula name
arr = Split(f, "!") 'get an array from splitting on !
arrWs = Split(arr(0), ":") 'get the start/end worksheet names
indx1 = ThisWorkbook.Worksheets(arrWs(0)).Index
indx2 = ThisWorkbook.Worksheets(arrWs(1)).Index
rngAddr = arr(1) '...and the range address
'size the output array
ReDim arrout(1 To Range(rngAddr).Rows.Count, 1 To 1 (indx2 - indx1))
For i = indx1 To indx2 'loop over the worksheets
data = ThisWorkbook.Sheets(i).Range(rngAddr).Value
For r = 1 To UBound(data)
arrout(r, i) = data(r, 1)
Next r
Next i
MyUDF = arrout 'return the array
End Function
uj5u.com熱心網友回復:
您可以使用:
=HSTACK(Sheet1:Sheet3!B1:B3)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/514482.html
上一篇:在VBA中拆分并寫入單元格
