|
按ALT+F11进入VBE界面分别将三个工作表代码名称(按F4从属性窗口设)设置为ws1、ws2、ws3,插入一个模块编写如下代码并将其加载到一个窗体控件即可。
Sub rk()
Dim rg As Range
Dim rg1 As Range
Dim x As Integer
Dim i As Integer
x = ws3.[a1].CurrentRegion.Rows.Count
Set rg = ws3.[c2:c65536]
Set rg1 = rg.Find(ws1.[g2])
If Not rg1 Is Nothing Then
MsgBox "此入库单已存在,请核准"
Exit Sub
End If
For i = 5 To 17
If ws1.Cells(i, 1) <> "" Then
ws3.Cells(x + 1, 1) = ws1.[b3]
ws3.Cells(x + 1, 2) = ws1.[g3]
ws3.Cells(x + 1, 3) = ws1.[g2]
ws1.Range(ws1.Cells(i, 1), ws1.Cells(i, 4)).Copy ws3.Cells(x + 1, 4)
ws1.Range(ws1.Cells(i, 5), ws1.Cells(i, 7)).Copy ws3.Cells(x + 1, 9)
x = x + 1
End If
Next i
MsgBox "此入库单已成功入库"
End Sub
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|