|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
这个只能VBA解决了,简单写了几句代码,点击按钮【计算重量】就可以了
- Sub JiSuanZhongLiang() '计算重量
- Dim i As Long, j As Integer, k As Integer
- Dim m As Integer
- Dim zRow As Long
- Dim benTi, benZhong As Double
- Dim jiaoTi, jiaoZhong As Double
-
- zRow = Sheets("型号重量表").Cells(Sheets("型号重量表").Rows.Count, 1).End(xlUp).Row
- For j = 4 To 19 Step 4 '循环明细表中每个型号
-
- For i = 2 To zRow
- If Cells(j, 5) = Sheets("型号重量表").Cells(i, 1) Then
-
- '计算本体重量
- benZhong = 0
- benTi = FenjieBentiBianhao(Cells(j, 7))
- For k = LBound(benTi) To UBound(benTi)
- benZhong = benZhong + Sheets("型号重量表").Cells(i, 1 + benTi(k))
- Next k
- Cells(j, 8) = benZhong
-
- '计算脚重
- For m = 0 To 3
- jiaoZhong = 0
- jiaoTi = FenjieBentiBianhao(Cells(j + m, 10))
- For k = LBound(jiaoTi) To UBound(jiaoTi)
- jiaoZhong = jiaoZhong + Sheets("型号重量表").Cells(i, 1 + jiaoTi(k))
- Next k
-
- Cells(j + m, 11) = jiaoZhong
-
- Next m
-
- Exit For
- End If
-
- Next i
- Next j
- End Sub
- Private Function FenjieBentiBianhao(bianHao As String) '分解本体编号
- '1~15+17+19
- Dim bArr, lianXu
- Dim result() As Integer, r As Integer
- Dim i As Integer, j As Integer
-
- bArr = Split(bianHao, "+")
-
- For i = LBound(bArr) To UBound(bArr)
-
- If InStr(bArr(i), "~") > 1 Then '分解1至15
-
- lianXu = Split(bArr(i), "~")
- For j = Int(lianXu(0)) To Int(lianXu(1))
- r = r + 1
- ReDim Preserve result(1 To r)
- result(r) = j
- Next j
-
- Else '分解单个整数
- r = r + 1
- ReDim Preserve result(1 To r)
- result(r) = Int(bArr(i))
- End If
- Next i
-
- FenjieBentiBianhao = result
-
- End Function
复制代码
|
|