하나의 통합 문서에서 개별 작업 주를 나타내는 일련의 동적 워크 시트가 있습니다. 이 워크 시트에는 데이터를 가져와 여러 배열 0-13에 저장하는 여러 드라이버가 있습니다. 그런 다음 이러한 배열은 데이터를 요약 목록에 출력하여 요약 시트에 출력합니다. 데이터는 날짜별로 분류되어 월별 통계가 가능합니다.배열에 데이터 보내기 : 형식이 일치하지 않습니다. VBA/Excel
간혹 "추가"드라이버가 있습니다. 이 드라이버는 또한 데이터를 캡처하고 요약해야합니다. 전용 드라이버와 달리 "추가 드라이버"는 차량 유형별로 데이터를 분류해야합니다.
내 조건, 추가 드라이버 확인 및 트럭 유형 확인, 작동. 추가 드라이버 용 배열은 그렇지 않습니다. 배열에서 데이터를 저장하려고 할 때 형식 불일치 오류가 발생합니다. 나 엄청 혼란스러워; 앞의 배열 0-9에 대해 동일한 형식을 유지했기 때문에 (모든 함수와 출력이 정상적으로 이루어지며 아래 코드에서 생략됩니다.)
셀의 내용을 검사했으며 그 값이 정확합니다. 그러나 배열에 이러한 형식으로 저장하려고하면 형식이 일치하지 않습니다.
이 배열에서 형식 불일치 오류의 원인은 무엇입니까? 구체적 ...
Dim arTemp
Dim arTemp1
Dim arTemp10
Dim list As Object, list1 As Object, list10 As Object
Dim d As Date
Dim x As Long, y As Integer
Dim ws As Worksheet
Set list = CreateObject("System.Collections.SortedList") 'Driver A
Set list1 = CreateObject("System.Collections.SortedList") 'Driver B
Set list10 = CreateObject("System.Collections.SortedList") '5-Ton Extra Drivers
Dim Truck5T As String, Truck3T As String, TruckC As String, StringCheck As String
Truck5T = "5-Ton"
For Each ws In Worksheets
If ws.Name <> "Summary" And ws.Name <> "WE Jan 08" Then
With ws
For y = 3 To 7
'Check for dates for each route
d = DateSerial(Year(.Cells(3, y)), Month(.Cells(3, y)), 1)
If list.containskey(d) Then
arTemp = list(d)
arTemp1 = list(d)
arTemp10 = list10(d)
Else
ReDim arTemp(13)
ReDim arTemp1(13)
ReDim arTemp10(13)
End If
arTemp(0) = arTemp(0) + .Cells(4, y) 'Grab # Deliveries (AM)
arTemp(1) = arTemp(1) + .Cells(5, y) 'Grab # of Pick Ups (AM)
arTemp(2) = arTemp(2) + .Cells(6, y) 'Grab # of Tires (AM)
arTemp(3) = arTemp(3) + .Cells(7, y) 'Grab Kilometres (AM)
arTemp(4) = arTemp(4) + .Cells(8, y) 'Grab # of Deliveries (PM)
arTemp(5) = arTemp(5) + .Cells(9, y) 'Grab # of Pick Ups (PM)
arTemp(6) = arTemp(6) + .Cells(10, y) 'Grab # of Tires (PM)
arTemp(7) = arTemp(7) + .Cells(11, y) 'Grab Kilometres (PM)
arTemp(8) = arTemp(8) + .Cells(12, y) 'Grab # of Deliveries (Total)
arTemp(9) = arTemp(9) + .Cells(13, y) 'Grab # of Pick Ups (Total)
arTemp(10) = arTemp(10) + .Cells(14, y) 'Grab # of Tires (Total)
arTemp(11) = arTemp(11) + .Cells(15, y) 'Grab Kilometres (Total)
arTemp(12) = arTemp(12) + .Cells(16, y) 'Grab Hours
arTemp(13) = arTemp(13) + 1
list(d) = arTemp
arTemp1(0) = arTemp1(0) + .Cells(4, y) 'Grab # Deliveries (AM)
arTemp1(1) = arTemp1(1) + .Cells(5, y) 'Grab # of Pick Ups (AM)
arTemp1(2) = arTemp1(2) + .Cells(6, y) 'Grab # of Tires (AM)
arTemp1(3) = arTemp1(3) + .Cells(7, y) 'Grab Kilometres (AM)
arTemp1(4) = arTemp1(4) + .Cells(8, y) 'Grab # of Deliveries (PM)
arTemp(5) = arTemp1(5) + .Cells(9, y) 'Grab # of Pick Ups (PM)
arTemp1(6) = arTemp1(6) + .Cells(10, y) 'Grab # of Tires (PM)
arTemp1(7) = arTemp1(7) + .Cells(11, y) 'Grab Kilometres (PM)
arTemp1(8) = arTemp1(8) + .Cells(12, y) 'Grab # of Deliveries (Total)
arTemp1(9) = arTemp1(9) + .Cells(13, y) 'Grab # of Pick Ups (Total)
arTemp1(10) = arTemp1(10) + .Cells(14, y) 'Grab # of Tires (Total)
arTemp1(11) = arTemp1(11) + .Cells(15, y) 'Grab Kilometres (Total)
arTemp1(12) = arTemp1(12) + .Cells(16, y) 'Grab Hours
arTemp1(13) = arTemp1(13) + 1
list1(d) = arTemp1
If .Cells(84, 2) <> "" Then
StringCheck = Left(.Cells(84, 2), 5)
If StringCheck = Truck5T Then
'5-ton (UpperL)
'first line below generates the type mismatch (cell value is what is expected from the worksheet)
arTemp10(0) = arTemp10(0) + .Cells(84 + 2, y) 'Grab # Deliveries (AM)
arTemp10(1) = arTemp10(1) + .Cells(84 + 3, y) 'Grab # of Pick Ups (AM)
arTemp10(2) = arTemp10(2) + .Cells(84 + 4, y) 'Grab # of Tires (AM)
arTemp10(3) = arTemp10(3) + .Cells(84 + 5, y) 'Grab Kilometres (AM)
arTemp10(4) = arTemp10(4) + .Cells(84 + 6, y) 'Grab # of Deliveries (PM)
arTemp10(5) = arTemp10(5) + .Cells(84 + 7, y) 'Grab # of Pick Ups (PM)
arTemp10(6) = arTemp10(6) + .Cells(84 + 8, y) 'Grab # of Tires (PM)
arTemp10(7) = arTemp10(7) + .Cells(84 + 9, y) 'Grab Kilometres (PM)
arTemp10(8) = arTemp10(8) + .Cells(84 + 10, y) 'Grab # of Deliveries (Total)
arTemp10(9) = arTemp10(9) + .Cells(84 + 11, y) 'Grab # of Pick Ups (Total)
arTemp10(10) = arTemp10(10) + .Cells(84 + 12, y) 'Grab # of Tires (Total)
arTemp10(11) = arTemp10(11) + .Cells(84 + 13, y) 'Grab Kilometres (Total)
arTemp10(12) = arTemp10(12) + .Cells(84 + 14, y) 'Grab Hours
arTemp10(13) = arTemp10(13) + 1
list10(d) = arTemp10
End If
End If
Next
End With
End If
Next
With Worksheets("Summary")
.Cells.Delete
For x = 0 To list.Count - 1 'Driver A
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, 5) = list(d)(2)
.Cells(x + 43, 6) = list(d)(3)
.Cells(x + 43, 7) = list(d)(4)
.Cells(x + 43, 8) = list(d)(5)
.Cells(x + 43, 9) = list(d)(6)
.Cells(x + 43, 10) = list(d)(7)
.Cells(x + 43, 11) = list(d)(8)
.Cells(x + 43, 12) = list(d)(9)
.Cells(x + 43, 13) = list(d)(10)
.Cells(x + 43, 14) = list(d)(11)
.Cells(x + 43, 15) = list(d)(12)
Next
For x = 0 To list.Count - 1 'Driver A
d = list.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, 5) = list1(d)(2)
.Cells(x + 43, 6) = list1(d)(3)
.Cells(x + 43, 7) = list1(d)(4)
.Cells(x + 43, 8) = list1(d)(5)
.Cells(x + 43, 9) = list1(d)(6)
.Cells(x + 43, 10) = list1(d)(7)
.Cells(x + 43, 11) = list1(d)(8)
.Cells(x + 43, 12) = list1(d)(9)
.Cells(x + 43, 13) = list1(d)(10)
.Cells(x + 43, 14) = list1(d)(11)
.Cells(x + 43, 15) = list1(d)(12)
Next
For x = 0 To list.Count - 1 'Additional Drivers: 5-Ton
d = list.getkey(x)
.Cells(x + 193, 1) = Year(d)
.Cells(x + 193, 2) = Month(d)
.Cells(x + 193, 3) = list10(d)(0)
.Cells(x + 193, 4) = list10(d)(1)
.Cells(x + 193, 5) = list10(d)(2)
.Cells(x + 193, 6) = list10(d)(3)
.Cells(x + 193, 7) = list10(d)(4)
.Cells(x + 193, 8) = list10(d)(5)
.Cells(x + 193, 9) = list10(d)(6)
.Cells(x + 193, 10) = list10(d)(7)
.Cells(x + 193, 11) = list10(d)(8)
.Cells(x + 193, 12) = list10(d)(9)
.Cells(x + 193, 13) = list10(d)(10)
.Cells(x + 193, 14) = list10(d)(11)
.Cells(x + 193, 15) = list10(d)(12)
Next
End With
코드 디버깅을 시도하십시오. 예 : 'arTemp10 (0)'의 원래 값은 얼마입니까? –
'list10 (d)'의 값은 무엇입니까? 내 읽기에 의해 배열이 아닌 빈'Variant'이어야합니다. – Comintern
arTemp10 (0)의 원래 값은 아무 것도 없습니다. 형식 불일치는 다음 위치에 있습니다. arTemp10 (0) = arTemp10 (0) + .Cells (84 + 2, y) 배열의 첫 번째 항목은 어느 것입니까? 셀의 데이터는 문제가 없습니다. 단순히 배열로 전달되지 않습니다. list10 (0)의 값은 arTemp10 (0)부터 arTemp10 (13)의 값이되며 그 중 13은 카운터이고 나머지는 워크 시트 셀에있는 데이터입니다. – WarOrdos