假设我有一个数组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
EDIT1
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
由于
答案 0 :(得分:5)
我们可以将字典项(数组)放入带有单个语句的范围中吗? 是,您可以将所有字典项放入范围。
试用此代码并清楚地解释 /评论您需要的任何更改:
<强>代码:强>
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
<强>输出:强>