|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
fasfdfdsfdasfdsfdsaf- Sub 统计采购进度()
- Dim arr As Variant, brr As Variant, crr() As Variant, theSum#
- Dim theStr1$, theStr2$, theDate1 As Date, theDate2 As Date, i&, j&, theFinalRow&
- arr = Sheet2.Cells(1).CurrentRegion '采购进度表
- If TypeName(arr) <> "Variant()" Then Exit Sub
- ReDim crr(1 To UBound(arr), 1 To 2)
- crr(1, 1) = arr(1, 8) '标题“到库数量”
- crr(1, 2) = arr(1, 9) '标题“采购进度情况”
- With Sheet1 '入库表
- theFinalRow = .Cells(.Rows.Count, 1).End(xlUp).Row
- If theFinalRow < 4 Then Exit Sub '前3行为标题行
- brr = .Range(.Cells(3, 1), .Cells(theFinalRow, 9))
- End With
- If TypeName(brr) <> "Variant()" Then Exit Sub
- For i = 2 To UBound(arr)
- theSum = 0
- theStr1 = arr(i, 1)
- If theStr1 <> "" Then
- theDate1 = arr(i, 7)
- For j = 2 To UBound(brr) '数组第1行为标题行
- theStr2 = brr(j, 4)
- If theStr2 = theStr1 Then
- theDate2 = brr(j, 9)
- If theDate2 >= theDate1 Then theSum = theSum + brr(j, 6)
- End If
- Next j
- End If
- If arr(i, 3) > 0 Then '第3列为计划采购数量
- If theSum >= arr(i, 3) Then
- crr(i, 1) = theSum
- crr(i, 2) = "已完成"
- Else
- If theSum = 0 Then
- crr(i, 2) = "未完成"
- Else
- crr(i, 1) = theSum
- crr(i, 2) = "部分完成"
- End If
- End If
- Else
- If theSum > 0 Then crr(i, 1) = theSum
- crr(i, 2) = "乱七八糟"
- End If
- Next i
- Sheet2.Cells(1, 8).Resize(UBound(crr), UBound(crr, 2)) = crr
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|