R
Rich
I'm using an array to save the total quantities of part numbers in various
sequences of a project. The code is shown below.
"a" = the shipping sequence number
aryTotK(a) = the total pieces of part "K" in sequence "a", etc.
If I have only one sheet of part numbers, the code works. If I copy that
sheet, leaving all data the same, my total quantities should be twice
compared to when I only have one sheet of parts. However, when I have more
than one sheet of parts, only the first "sequence" has the correct number of
parts (the total pieces of all part lists), the rest of the sequences only
contain the quantity on the last page of the part lists. When I step thru
the code, I notice that, on part lists after the first one, when "a" is
greater than 1, the "aryTotK(a)" value is a "subscript out of range" until it
after the "redim" command.
Why does it only keep the values from the previous part lists when a=1??
**********************************
a = 1
ReDim aryTotK(a)
ReDim aryTotLH(a)
ReDim aryTotG(a)
ReDim aryTotJS(a)
ReDim aryTotHDR(a)
ReDim aryTotBR(a)
For Each wks In ThisWorkbook.Worksheets
If UCase(wks.Name) Like "S (*)" Then
'***count total quantities of marks
If wks.Range("R1").Value = "M" Then
For a = 1 To iSeqCt
ReDim Preserve aryTotK(a)
ReDim Preserve aryTotLH(a)
ReDim Preserve aryTotG(a)
ReDim Preserve aryTotJS(a)
ReDim Preserve aryTotHDR(a)
ReDim Preserve aryTotBR(a)
For iCol = 2 To 15
If wks.Range(Chr(64 + iCol) + Replace(Str(13), " ", "")).Value =
arySeqList(a) Then
For iRow = 14 To 49
c = ""
For b = 1 To iMkCt - 1
If wks.Range("A" + Replace(Str(iRow), " ", "")).Value = aryJstMk(b)
Then
c = aryMemType(b)
Exit For
End If
Next b
Select Case c
Case "K"
aryTotK(a) = aryTotK(a) + wks.Range(Chr(64 + iCol) +
Replace(Str(iRow), " ", "")).Value
Case "LH"
aryTotLH(a) = aryTotLH(a) + wks.Range(Chr(64 + iCol) +
Replace(Str(iRow), " ", "")).Value
Case "G"
aryTotG(a) = aryTotG(a) + wks.Range(Chr(64 + iCol) +
Replace(Str(iRow), " ", "")).Value
Case "JS"
aryTotJS(a) = aryTotJS(a) + wks.Range(Chr(64 + iCol) +
Replace(Str(iRow), " ", "")).Value
Case "HDR"
aryTotHDR(a) = aryTotHDR(a) + wks.Range(Chr(64 + iCol) +
Replace(Str(iRow), " ", "")).Value
Case "BR"
aryTotBR(a) = aryTotBR(a) + wks.Range(Chr(64 + iCol) +
Replace(Str(iRow), " ", "")).Value
End Select
Next iRow
End If
Next iCol
Next a
End If
*****************************
sequences of a project. The code is shown below.
"a" = the shipping sequence number
aryTotK(a) = the total pieces of part "K" in sequence "a", etc.
If I have only one sheet of part numbers, the code works. If I copy that
sheet, leaving all data the same, my total quantities should be twice
compared to when I only have one sheet of parts. However, when I have more
than one sheet of parts, only the first "sequence" has the correct number of
parts (the total pieces of all part lists), the rest of the sequences only
contain the quantity on the last page of the part lists. When I step thru
the code, I notice that, on part lists after the first one, when "a" is
greater than 1, the "aryTotK(a)" value is a "subscript out of range" until it
after the "redim" command.
Why does it only keep the values from the previous part lists when a=1??
**********************************
a = 1
ReDim aryTotK(a)
ReDim aryTotLH(a)
ReDim aryTotG(a)
ReDim aryTotJS(a)
ReDim aryTotHDR(a)
ReDim aryTotBR(a)
For Each wks In ThisWorkbook.Worksheets
If UCase(wks.Name) Like "S (*)" Then
'***count total quantities of marks
If wks.Range("R1").Value = "M" Then
For a = 1 To iSeqCt
ReDim Preserve aryTotK(a)
ReDim Preserve aryTotLH(a)
ReDim Preserve aryTotG(a)
ReDim Preserve aryTotJS(a)
ReDim Preserve aryTotHDR(a)
ReDim Preserve aryTotBR(a)
For iCol = 2 To 15
If wks.Range(Chr(64 + iCol) + Replace(Str(13), " ", "")).Value =
arySeqList(a) Then
For iRow = 14 To 49
c = ""
For b = 1 To iMkCt - 1
If wks.Range("A" + Replace(Str(iRow), " ", "")).Value = aryJstMk(b)
Then
c = aryMemType(b)
Exit For
End If
Next b
Select Case c
Case "K"
aryTotK(a) = aryTotK(a) + wks.Range(Chr(64 + iCol) +
Replace(Str(iRow), " ", "")).Value
Case "LH"
aryTotLH(a) = aryTotLH(a) + wks.Range(Chr(64 + iCol) +
Replace(Str(iRow), " ", "")).Value
Case "G"
aryTotG(a) = aryTotG(a) + wks.Range(Chr(64 + iCol) +
Replace(Str(iRow), " ", "")).Value
Case "JS"
aryTotJS(a) = aryTotJS(a) + wks.Range(Chr(64 + iCol) +
Replace(Str(iRow), " ", "")).Value
Case "HDR"
aryTotHDR(a) = aryTotHDR(a) + wks.Range(Chr(64 + iCol) +
Replace(Str(iRow), " ", "")).Value
Case "BR"
aryTotBR(a) = aryTotBR(a) + wks.Range(Chr(64 + iCol) +
Replace(Str(iRow), " ", "")).Value
End Select
Next iRow
End If
Next iCol
Next a
End If
*****************************