|
可以根据不同的“CIRCUIT品番”检查数据
- Sub CheckData()
- Dim vData As Variant, nRow As Integer, nCol As Integer
- Dim vFill As Variant, nI As Integer
- Dim dicData As Object, dicItem As Object
- Dim sItem As String, sCircuit As String, nAmount As Double
- Dim nItemErr As Double, nAmountErr As Double, sKey As String
-
- Set dicItem = CreateObject("Scripting.Dictionary")
- Set dicData = CreateObject("Scripting.Dictionary")
- vData = Sheet1.UsedRange.Value
- For nRow = 3 To UBound(vData)
- sItem = Trim(vData(nRow, 2))
- If sItem <> "" Then dicItem(sItem) = nRow
- For nCol = 6 To UBound(vData, 2)
- If Trim(vData(nRow, nCol)) <> "" Then
- nAmount = Val(vData(nRow, nCol))
- For nI = 3 To 4
- sCircuit = Trim(vData(nI, nCol))
- If sItem <> "" And sCircuit <> "" Then dicData(sCircuit & "|" & sItem) = nAmount
- Next
- End If
- Next
- Next
- If dicData.Count = 0 Then
- MsgBox "没有“合并BOM”资料!"
- Exit Sub
- End If
- With Sheet2
- sCircuit = Trim(.[B1].Value)
- If sCircuit = "" Then
- MsgBox "未填“CIRCUIT品番”! "
- .[B1].Select
- Else
- vData = .[A1].CurrentRegion.Value
- If UBound(vData) > 4 Then
- ReDim vFill(5 To UBound(vData), 1 To 4)
- For nRow = 5 To UBound(vData)
- sItem = Trim(vData(nRow, 2))
- If dicData.Exists(sCircuit & "|" & sItem) Then vFill(nRow, 3) = dicData(sCircuit & "|" & sItem)
- If sItem <> "" Then
- If dicItem.Exists(sItem) Then
- vFill(nRow, 1) = sItem
- vFill(nRow, 2) = True
- Else
- vFill(nRow, 1) = "Error"
- vFill(nRow, 2) = False
- nItemErr = nItemErr + 1
- End If
- vFill(nRow, 4) = vFill(nRow, 3) = Val(vData(nRow, 6))
- nAmountErr = nAmountErr - (Not vFill(nRow, 4)) * 1
- End If
- Next
- .[H1] = nItemErr
- .[J1] = nAmountErr
- .[G5].Resize(UBound(vData) - 4, 4) = vFill
- MsgBox "OK!"
- Else
- MsgBox "没有数据!"
- End If
- End If
- End With
- End Sub
复制代码 |
|