|
- Option Explicit
- Dim 采购合同编号 As String
- Dim 物料编码 As String
- Dim 任务编号 As String
- Dim Flag As Boolean
- Sub 保存()
- Dim R%, i%, a(), n%
- If ActiveSheet.Name <> "登记" Then Sheets("登记").Select
- If Not IsDate(Range("K3")) Then MsgBox "请输入正确的“安排日期”!": Exit Sub
- R = Range("B65536").End(3).Row
- If R < 7 Then MsgBox "没有要保存的数据!": Exit Sub
- On Error Resume Next
- For i = 7 To R
- Main Cells(i, 2), Cells(i, 3), Cells(i, 4), Cells(i, 6), Cells(i, 7)
- If Flag Then MsgBox "数据匹配错误。保存失败!": Exit Sub
- n = n + 1: ReDim Preserve a(1 To 20, 1 To n)
- a(1, n) = 物料编码
- a(2, n) = Range("G3") '总序号
- a(3, n) = 任务编号
- a(4, n) = Range("G4") '产品类别
- a(5, n) = Range("C4") '合同编号
- a(6, n) = Range("C3") '客户
- a(7, n) = Range("K3") '安排日期
- a(8, n) = Range("K4") '交货日期
- a(9, n) = Cells(i, 5) '安排数量
- a(10, n) = Cells(i, 2) '件号
- a(11, n) = Cells(i, 8) '客户型号
- a(12, n) = Cells(i, 9) '生产型号
- a(13, n) = Cells(i, 6) '外径
- a(14, n) = Cells(i, 7) '厚度
- a(15, n) = Cells(i, 10) '序1
- a(16, n) = Cells(i, 11) '序2
- a(17, n) = Cells(i, 3) '材料
- a(18, n) = Cells(i, 4) '材料厂家
- a(19, n) = 采购合同编号
- a(20, n) = Cells(i, 12) '备注
- Next
- Sheet1.Range("A65536").End(3).Offset(1, 0).Resize(n, 20) = WorksheetFunction.Transpose(a)
- End Sub
- Private Function Main(件号 As String, 材料 As String, 材料厂家 As String, 外径 As Single, 厚度 As Single)
- Flag = False
- Dim a(7) As String
- On Error GoTo ErrLint
- a(0) = Format(Range("K3"), "mmdd") '安排日期
- a(1) = Format(外径 * 100, "00000")
- a(2) = Format(厚度 * 100, "0000")
- a(3) = Mid(件号, 3, 1)
- a(4) = Sheet2.Range("D:D").Find(材料, Lookat:=xlWhole).Offset(0, 1)
- a(5) = Sheet2.Range("I:I").Find(材料厂家, Lookat:=xlWhole).Offset(0, 1)
- a(6) = Sheet2.Range("I:I").Find(材料厂家, Lookat:=xlWhole).Offset(0, 2)
- a(7) = "00" '待确认——采购合同编号的第4、5位指向任务表的“安排日期”是什么意思?
- 采购合同编号 = a(0) & a(7) & a(6)
- 物料编码 = a(1) & a(2) & "-" & a(3) & a(4) & a(5) & "-" & a(0)
- 任务编号 = Format(Range("G3"), "0000") & "-" & a(3) & a(4) & a(5)
- Exit Function
- ErrLint:
- Flag = True
- End Function
复制代码 |
|