|
收发类别有数据时,保存到以下明细中,为什么只保存了第一项数据,2/3/4项,保存不了?
代码中是去掉15行呀,没错呀,为什么会卡在这里运行不下去?
如果只录入第1项数据,代码是没问题 的,从第2项,有数据时就不行了,求助哪位大神指点下……谢谢
代码如下:
Dim Rng As Range
Dim arr As Variant, brr As Variant
Dim i As Long, j As Long, r As Long
If Range("C5") = "" Then MsgBox "请输入日期": Exit Sub
If Range("C4") = "" Then MsgBox "请输入部门": Exit Sub
If Range("G5") = "" Then MsgBox "请输入负表人": Exit Sub
If Range("G4") = "" Then MsgBox "请输入单号": Exit Sub
Set Rng = Sheets("订单明细").Columns(4).Find([G4].Value, lookat:=xlWhole) ' H4=订单明细第4行
If Not Rng Is Nothing Then '当单号已经存在的时候
MsgBox "该单号已经添加“生产订单明细”表内"
Exit Sub
End If
Application.ScreenUpdating = False
arr = Array("B5", 2, "C4", 3, "G4", 4, "G5", 10, "C5", 11, "F12", 12, "D12", 13)
brr = Array(3, 5, 4, 6, 5, 7, 6, 8, 7, 9)
For j = 8 To 11
If Len(Cells(j, 3)) > 0 Then '录入窗第3列
r = Sheets("订单明细").Cells(Rows.Count, 2).End(3).Row + 1
Sheets("订单明细").Cells(r, 1) = r - 15 ’r=行 -15行
For i = LBound(arr) To UBound(arr) Step 2
Sheets("订单明细").Cells(r, arr(i + 1)) = Range(arr(i))
Next i
For i = LBound(brr) To UBound(brr) Step 2
Sheets("订单明细").Cells(r, brr(i + 1)) = Cells(j, brr(i))
Next i
End If
Next j
MsgBox "录入成功"
Range("C5") = ""
Range("C4") = ""
Range("G5") = ""
Range("G4") = ""
|
|