|
楼主 |
发表于 2009-4-27 16:22
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
这是单行录入的代码,使用起来也不太方便。
1、保存信息按钮的代码:
Option Explicit
Dim mRow
Public mDel As Boolean
Sub 矩形27_单击() '信息录入-保存信息
Dim mName
Dim rng As Range, arr(13)
Sheets("信息录入").Shapes("Rectangle 27").Select
mName = Selection.Characters.Text '"保存修改"
Application.ScreenUpdating = False
With Sheets("信息录入")
For Each rng In .Range("A5,F5,K15")
If Len(rng.Value) = 0 Then
MsgBox "货号、单位和操作人员必须要填写,请检查!", vbExclamation, Split(ThisWorkbook.Name, ".xls")(0)
rng.Select
Exit Sub
End If
Next
arr(1) = .[A5]
arr(2) = .[B5]
arr(3) = .[C5]
arr(4) = .[D5]
arr(5) = .[E5]
arr(6) = .[F5]
arr(7) = .[G5]
arr(8) = .[H5]
arr(9) = .[I5]
arr(10) = .[J5]
arr(11) = .[K5]
arr(12) = .[K15] ’每行都一样
arr(13) = .[B2]’每行都一样
End With
If MsgBox("您确认数据都准确无误吗?", 4 + 64, "保存提示") = vbYes Then
Select Case mName
Case "保存信息"
With Sheets("产品数据库")
If Application.WorksheetFunction.CountIf(.Range("B:B"), Sheets("信息录入").[A5]) > 0 Then
MsgBox "货号: " & Sheets("信息录入").[A5] & " 已存在,请检查!", vbExclamation, Split(ThisWorkbook.Name, ".xls")(0)
GoTo lab2
End If
arr(0) = "=row()-1"
.Unprotect "0000"
.Range("a" & .[a65536].End(xlUp).Row + 1).Resize(1, 14) = arr
.Protect "0000"
End With
[K2] = "已保存"
Application.ScreenUpdating = True
MsgBox "货号: " & Sheets("信息录入").[A5] & " 保存完毕!", vbInformation, Split(ThisWorkbook.Name, ".xls")(0)
Case "保存修改"
With Sheets("产品数据库")
arr(0) = "=row()-1"
.Unprotect "0000"
.Range("a" & mRow).Resize(1, 14) = arr
.Protect "0000"
End With
[K2] = "已修改保存"
Application.ScreenUpdating = True
MsgBox "货号: " & Sheets("信息录入").[A5] & " 修改完毕!", vbInformation, Split(ThisWorkbook.Name, ".xls")(0)
mDel = True
End Select
lab2:
Selection.Characters.Text = "保存信息"
Sheets("信息录入").Shapes("Rectangle 27").Select
End If
2、查询修改按钮的代码:
End Sub
Sub 矩形28_单击() '信息录入-查询修改
Dim mIn, arr
mIn = InputBox(Chr(13) & Chr(13) & Chr(13) & Chr(13) & "请输入要查询修改的'货号':", Split(ThisWorkbook.Name, ".xls")(0) & "--查询修改")
If mIn = "" Then Exit Sub
On Error GoTo lab1
With Sheets("产品数据库")
mRow = .Range("B:B").Find(what:=mIn, Lookat:=xlWhole).Row
arr = .Range("A" & mRow & ":N" & mRow)
End With
With Sheets("信息录入")
.Range("A5,B5,C5,D5,E5,F5,G5,H5,I5,J5,K5,K15,B2") = ""
.[A5] = arr(1, 2)
.[B5] = arr(1, 3)
.[C5] = arr(1, 4)
.[D5] = arr(1, 5)
.[E5] = arr(1, 6)
.[F5] = arr(1, 7)
.[G5] = arr(1, 8)
.[H5] = arr(1, 9)
.[I5] = arr(1, 10)
.[J5] = arr(1, 11)
.[K5] = arr(1, 12)
.[K15] = arr(1, 13)
.[B2] = arr(1, 14)
.Shapes("Rectangle 27").Select
Selection.Characters.Text = "保存修改"
.[C21].Select
mDel = False
End With
[K2] = "查询修改中"
Exit Sub
lab1:
MsgBox "你要查询修改的货号: " & mIn & " 不存在,请检查!", vbExclamation, Split(ThisWorkbook.Name, ".xls")(0) & "-查询修改"
End Sub
3、清空并继续按钮的代码:
Private Sub CommandButton2_Click()
If MsgBox("您确认已经保存了吗?", 4 + 64, "清除提示") = vbYes Then
Range("A5:K5,B2,K15") = ""
[K2] = "未保存"
ActiveSheet.Shapes("Rectangle 27").Select
Selection.Characters.Text = "保存信息"
End If
End Sub |
|