複数のワークシートから1つのワークブックの要約シートに印刷するためのデータを取得している配列があります。アレイは、コードをステップ実行するときに、すべてのシートを通して正しいデータを取得しているようです。配列は、ループを通過するたびにソートされたリストに情報を保存する必要があります。ソートされたリストが印刷されない:VBAからExcel
ソースデータは、2人の作業者を表す2つの横並び(水平)セクションで構成されています。各作業者のデータは、形式化の点で同一です。
私のリストは要約ページに印刷されておらず、list.countに問題があるようです。 list.count -1を指定すると、forループはまったく実行されません。 -1を省略すると、ループの1回のパスが得られます。
リストがリストに保存されているか、リストの出力がサマリーシートに表示されている場合、どのような問題がありますか?
Dim arTemp
Dim arTemp1
Dim d As Date
Dim x As Long, Y As Integer
Dim ws As Worksheet
Dim list As Object, list1 As Object
Set list = CreateObject("System.Collections.SortedList")
Set list1 = CreateObject("System.Collections.SortedList")
For Each ws In Worksheets
If ws.Name <> "Summary" And ws.Name <> "SheetX" Then
With ws
For y = 3 to 7
d=DateSerial(Year(.Cells(3,y)), Month(.Cells(3,y)),1
If List.containskey(d) then
arTemp = list(d)
arTemp1 = list1(d)
Else
ReDim arTemp(13)
ReDim arTemp1(13)
End If
arTemp(0) = arTemp(0) + .Cells(4,y)
arTemp(1) = arTemp(1) + .Cells(5,y)
arTemp(2) = arTemp(2) + .Cells(6,y)
.
.
.
arTemp(12) = arTemp(12) + .Cells(16,y)
arTemp(13) = arTemp(13) + 1
list(d) = arTemp
arTemp1(0) = arTemp1(0) + .Cells(4,y + 11)
arTemp1(1) = arTemp1(1) + .Cells(5,y + 11)
arTemp1(2) = arTemp1(2) + .Cells(6,y + 11)
.
.
.
arTemp1(12) = arTemp1(12) + .Cells(16,y + 11)
arTemp1(13) = arTemp1(13) + 1
list1(d) = arTemp1
Next
End With
End If
Next
With Worksheets("Summary")
.Cells.Delete
For x = 0 To list.Count - 1
d = list.getkey(x)
.Cells(x + 43, 1) = Year(d)
.Cells(x + 43, 2) = Month(d)
.Cells(x + 43, 3) = list(d)(0)
.Cells(x + 43, 4) = list(d)(1)
.
.
.
.Cells(x +43, 15) = list(d)(12)
Next
For x = 0 To list.Count - 1
d = list1.getkey(x)
.Cells(x + 43, 1) = Year(d)
.Cells(x + 43, 2) = Month(d)
.Cells(x + 43, 3) = list1(d)(0)
.Cells(x + 43, 4) = list1(d)(1)
.
.
.
.Cells(x +43, 15) = list1(d)(12)
Next
End With