|
楼主 |
发表于 2024-5-31 16:36
|
显示全部楼层
学习了下写VBA 我太难了 求老师帮我改:
Sub 产能分配()
Dim ARR, BRR, CRR, I As Integer, J As Integer, irow%, icol%, f(1 To 25)
irow = Range("b65536").End(xlUp).Row
icol = Cells(1, Columns.Count).End(xlToLeft).Column
ARR = Range(Cells(1, 22), Cells(1, icol)) '端子组总工时入横向数组
BRR = Range(Cells(2, 22), Cells(2, icol)) '成型组总工时入横向数组
CRR = Range("m12:v" & irow) '组别入竖向数组
Dim sum As Double
Set d = CreateObject("Scripting.Dictionary")
For J = 3 To 3 'irow - 11
If CRR(J, 1) = "端子组" Then
For I = 1 To icol - 23
f(I) = CRR(J, 10) * ARR(1, I + 2)
sum = sum + f(I)
If CRR(J, 7) - sum > 0 And CRR(J, 7) - sum >= f(I) Then
f(I) = f(I)
Else
If CRR(J, 7) - sum > 0 And CRR(J, 7) - sum < f(I) Then
f(I) = CRR(J, 7) - sum
Else
f(I) = ""
End If
End If
Next
Range(Cells(14, 24), Cells(14, icol)) = (f) ' WorksheetFunction.Transpose(f)
Else
' ff(J) = CRR(J, 10) * BRR(1, J)
For I = 1 To icol - 23
f(I) = CRR(J, 10) * ARR(2, I + 2)
sum = sum + f(I)
If CRR(J, 7) - sum > 0 And CRR(J, 7) - sum >= f(I) Then
f(I) = f(I)
Else
If CRR(J, 7) - sum > 0 And CRR(J, 7) - sum < f(I) Then
f(I) = CRR(J, 7) - sum
Else
f(I) = ""
End If
End If
Next
End If
Next
icol2 = Cells(14, 24).End(xlToRight).Column
Range(Cells(15, icol2), Cells(15, icol)) = (f) ' WorksheetFunction.Transpose(f)
End Sub |
|