|
|
- Sub test()
- Dim myarray() As String, i As Long, index As Long, k As String, st As Double
- Dim k1 As Range, lastRowE As Long, lastRowA As Long
-
- lastRowE = Cells(Rows.Count, 5).End(xlUp).Row 'E列最后有效行
- lastRowA = Cells(Rows.Count, 1).End(xlUp).Row 'A列最后有效行
-
- For i = 2 To lastRowA
- st = 0
- If Cells(i, 1) <> "" Then
- myarray = Split(Cells(i, 1), "/")
-
- For index = LBound(myarray) To UBound(myarray)
- k = Trim(myarray(index)) '去除空格
- If k <> "" Then '跳过空值
- Set k1 = Range("E2:E" & lastRowE).Find(k, LookIn:=xlValues, LookAt:=xlWhole)
- If Not k1 Is Nothing Then
- st = st + k1.Offset(0, 1).Value 'F列值累加
- 'Else
- '可选:记录未找到的编码
- 'Debug.Print "编码 " & k & " 不存在"
- End If
- End If
- Next index
-
- Cells(i, 2) = st
- End If
- Next i
- End Sub
复制代码 |
|