|
楼主 |
发表于 2017-4-27 21:18
|
显示全部楼层
修改并添加查询代码:- Sub 送检制单()
- Application.ScreenUpdating = False
- lsc
- Dim y As String, Dh As String, T As String, i
- y = "SJ" & Format(Now, "yyyymm")
- With Sheets("送检制单")
- .Range("G3") = y
- .Range("C7") = Format(Now, "yyyy/mm/dd hh:mm")
- T = Application.WorksheetFunction.Text(.Range("H3"), "000")
- Dh = .Range("G3") & T
- If .Range("C5") = "" Then
- MsgBox "请选择送检人"
- End
- End If
- End With
- If Sheets("送检制单").Range("B10").Value = "" Then
- MsgBox "请输入零件号"
- End
- End If
- If Sheets("送检制单").Range("E10").Value = "" Then
- MsgBox "请输入数量"
- End
- Else
- For i = 10 To 19
- If Cells(i, 2) <> "" Then
- With Sheets("送检记录")
- r = .Cells.Find("*", , , , xlByRows, xlPrevious).Row + 1
- .Cells(r, 1) = Range("C7") '发货日期
- .Cells(r, 2) = Cells(i, 2) '零件简码
- .Cells(r, 3) = Cells(i, 3) '零件名称
- .Cells(r, 4) = Cells(i, 4) '图号
- .Cells(r, 5) = Cells(i, 5) '送检数量
- .Cells(r, 6) = Cells(i, 6) '炉号
- .Cells(r, 7) = Cells(i, 7) '批号
- .Cells(r, 8) = Cells(i, 8) '供应商
- .Cells(r, 9) = Dh '单号
- .Cells(r, 10) = Range("C5") '送检人
- End With
- End If
- Next
- End If
- With Sheets("送检制单")
- '.PrintOut Copies:=1
- .Range("H3") = T + 1
- .Range("C5") = ""
- .Range("B10:H19").ClearContents
- End With
- 'ActiveWorkbook.Save
- Application.ScreenUpdating = True
- 'ActiveWorkbook.Close savechanges:=ture
- End Sub
- Sub lsc()
- Set d = CreateObject("Scripting.Dictionary")
- arr = Sheet1.[a1].CurrentRegion
- For i = 2 To UBound(arr)
- d(arr(i, 1)) = arr(i, 2) & "/" & arr(i, 3) & "/" & arr(i, 4)
- Next
- brr = Range("a10:h" & Cells(Rows.Count, 1).End(3).Row)
- For i = 1 To UBound(brr)
- If d.exists(brr(i, 2)) Then
- s = Split(d(brr(i, 2)), "/")
- Cells(i + 9, 3) = s(0)
- Cells(i + 9, 4) = s(1)
- Cells(i + 9, 8) = s(2)
- End If
- Next
- Set d = Nothing
- End Sub
复制代码
VBA触发代码范围设置问题
http://club.excelhome.net/thread-1342563-1-1.html
(出处: ExcelHome技术论坛)
|
|