gpt4 book ai didi

excel - 我们可以用一条语句将字典项(数组)放入 Range 中吗?

转载 作者:行者123 更新时间:2023-12-04 21:02:57 24 4
gpt4 key购买 nike

假设我确实有一个数组 A1(6)=(45,25,,36,88),A2(6)=(14,25,11),A3(6)=(11,21,20,25,48 )。现在我们可以借助单个语句(例如将单个数组赋值给一行)来放置这些数组值,就像这里的所有行到 Excel 的一个范围一样,在这里说“C1:R3”范围。

Dim R
R = Split(Join(A1, ",") & "," & Join(A2, ",") & "," & Join(A3, ","), ",")
Range("C5:T5").Value = R

现在我们可以将字典项(它是一个数组)组合成一个一维数组并分配回一个范围吗?
For Each ChilID In ChildIDs

Redim ChildDetailArray(ArrIndex)
ChildMatchNum=objExcel1.Application.WorksheetFunction.Match(ChilID, ob3.Columns(1), 0)
ChildDetailArray=ob1.Range(ob1.Cells(ChildMatchNum,1),ob1.Cells(ChildMatchNum,ArrIndex+1)).Value
ChildDic.Add ChilID,ChildDetailArray '(ChildDetailArray is an array)

Next

编辑1
      suppose a process#20 has 2 child processes say #12,#13. now i used a dictionary object Dic

Dic(12)=Arr(10,11,,,18) 'child details
Dic(13)=Arr(5,8,9,,,) ' child details

***Output:*** `1D array say ArrMerger()=(10,11,,,18,5,8,9,,,)`

以上 For Loop正在做同样的事情。现在当 Loop将完成,我希望那些作为 Dic(12) 和 Dic(13) 项目的子详细信息需要收集在一维数组中

更新
      strJoin = ","
For ChildKey In ChildDic.Keys

strJoin=Join(ChildDic(ChildKey),",") & strJoin

Next

谢谢

最佳答案

我们可以用一条语句将字典项(数组)放入 Range 中吗? 是的,您可以将所有字典项放入一个范围内。

试试这段代码并解释显然 /评论您需要的任何更改:

代码:

Option Explicit

Sub getMerged1DItems()
Dim d As Object, d2 As Object
Dim vArr As Variant
Dim vArr2 As Variant
Dim strJoin As String

Set d = CreateObject("Scripting.Dictionary")
Set d2 = CreateObject("Scripting.Dictionary")

'-- assume you have items in your dictionary
d.Add "Names", 1
d.Add "Titles", 2
d.Add "Jobs", 3
d.Add "Education", 4
d.Add "Experience", 5

'-- add dictionary items into an 1D array
vArr = d.Keys

'-- add 1D arryas into d2 dictionary as items
d2("v" & 1) = vArr
d2("v" & 2) = vArr

'-- join multiple 1D array items into one string delimitted by comma
strJoin = Join(d2("v" & 1), ", ") & "," & Join(d2("v" & 2), ", ")

'-- split the string by comma delimiter
vArr2 = Split(strJoin, ",")

'-- output to sheet using first 1D Array
Sheets(1).Range("B2").Resize(1, _
UBound(Application.Transpose(vArr))) = vArr

'-- output to sheet using dictionary
Sheets(1).Range("B4").Resize(1, _
UBound(Application.Transpose(d.Keys))) = d.Keys

'output to sheet using mergeed 1D array
Sheets(1).Range("B7").Resize(1, _
UBound(Application.Transpose(vArr2))) = vArr2

Set d2 = Nothing
Set d = Nothing

End Sub

输出:

enter image description here

关于excel - 我们可以用一条语句将字典项(数组)放入 Range 中吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32522071/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com