|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
"工程服務單"的TextBox我刪除了
改用 Label 和 ComboBox替代
"工程服務單"里的代码
- Private Sub CommandButton1_Click() '查询
- Dim Sh As Worksheet, i As Long
- Dim AB$, c As Object, fadd$, N
- Set Sh = Sheets("数据集")
- With Sh.Range("B3:B" & Sh.Cells(Sh.Rows.Count, 1).End(xlUp).Row)
- Set c = .Find(ComboBox1, LookIn:=xlValues, lookat:=xlWhole)
- If c Is Nothing Then
- MsgBox "找不到单号:" & [AB2], vbInformation + vbOKOnly
- Else
- [AB2] = c '单号
- [B6] = c.Offset(, 1) '客户
- [R6] = c.Offset(, 2) '地址
- [AC6] = c.Offset(, 3) '连络人/连糸方式
- [C7] = c.Offset(, 4) '项目名称
- [T7] = c.Offset(, 5) '机台编号
- [C8] = Year(c.Offset(, 7)) '制造年
- [F8] = Month(c.Offset(, 7)) '制造月
- [I8] = Day(c.Offset(, 7)) '制造日
- N = Split(c.Offset(, 8), " ~ ") '服务起止时间
- [Q8] = Year(N(0)) '年
- [T8] = Month(N(0)) '月
- [W8] = Day(N(0)) '日
- [Y8] = Hour(N(0)) '时
- [AA8] = Minute(N(0)) '分
- [AD8] = Month(N(1)) '月
- [AF8] = Day(N(1)) '日
- [AH8] = Hour(N(1)) '时
- [AJ8] = Minute(N(1)) '分
- [E10] = c.Offset(, 11) '故障现象
- [E13] = c.Offset(, 12) '处理过程
- [E16] = c.Offset(, 13) '改善建议
- [AC19] = c.Offset(, 15) '其它
- [M20] = c.Offset(, 18) '其它補充
- [AA21] = c.Offset(, 19) '客户签名
- [AG21] = c.Offset(, 20) '服务人员
- [AG22] = c.Offset(, 21) '服务时间
- If c.Offset(, 6) = [AE7] Then '服务类别
- [AD7] = "■"
- Else
- [AH7] = "■"
- End If
- If c.Offset(, 10) = [AD9] Then '备件使用
- [AC9] = "■"
- Else
- [AH9] = "■"
- End If
- For i = 4 To 27
- If c.Offset(, 9) = Cells(9, i) Then Cells(9, i - 1) = "■" '服务类型
- If c.Offset(, 14) = Cells(19, i) Then Cells(19, i - 1) = "■" '服务工作结果
- Next i
- For i = 3 To 9 Step 2
- If c.Offset(, 16) = Cells(20, i) Then Cells(21, i) = "ν" '服务技能
- If c.Offset(, 17) = Cells(20, i) Then Cells(22, i) = "ν" '服务态度
- Next i
- End If
- End With
- End Sub
- Private Sub CommandButton2_Click() '新单
- Dim Sh As Worksheet
- Dim AB$, c As Object, fadd$, NO
- ComboBox1.Visible = False
- Label1.Visible = True
- Label1.Caption = "" '单号
- [C3,C4,AB2,E4,B6:N6,R6:V6,AC6:AK6,C7:O7,T7:Y7,C8:D8,F8:G8,I8,Q8:R8,T8:U8,W8,Y8,AA8,AD8,AF8,AH8,AJ8] = ""
- [E10:AK18,AC19:AK19,C21:I22,M20:Z22,AA21:AF22,AG21:AK21] = ""
- [AD7,AH7,C9,J9,K9,O9,R9,U9,AC9,AH9,D19,I19,O19,V19,Z19] = "□"
- Set Sh = Sheets("数据集")
- AB = "JC" & Format(Date, "yyyymmdd")
- With Sh.Range("B3:B" & Sh.Cells(Sh.Rows.Count, 1).End(xlUp).Row)
- Set c = .Find(AB, LookIn:=xlValues, lookat:=xlPart)
- If Not c Is Nothing Then
- fadd = c.Address
- Do
- If Right(c, 5) > NO Then NO = Right(c, 5)
- Set c = .FindNext(c)
- Loop While Not c Is Nothing And c.Address <> fadd
- Else
- NO = ""
- End If
- End With
- If NO = "" Then
- Label1.Caption = "JC" & Format(Date, "yyyymmdd") & "00001" '新单编号
- Else
- Label1.Caption = AB & Format(NO + 1, "00000")
- End If
- [AB2] = Label1.Caption 'AB2单号
- CommandButton3.Enabled = True
- End Sub
- Private Sub CommandButton3_Click() '存储
- Dim Sh As Worksheet, r As Long, dic As Object, i As Long
- Dim D1, D2, ST$, SF$, SP4, SK$, SR$, SA$
- If [Z19] = "■" And [AC19] = "" Then
- MsgBox [Z20] & [A19] & "不可空白", vbInformation + vbOKCancel
- [AC19].Select
- Exit Sub
- End If
- If [AG21] = "" Then
- MsgBox [AG20] & "不可空白", vbInformation + vbOKCancel
- [AG21].Select
- Exit Sub
- End If
- If [AG22] = "" Then
- MsgBox "AG22请填写服务时间", vbInformation + vbOKCancel
- [AG22].Select
- Exit Sub
- End If
- Set Sh = Sheets("数据集")
- r = Sh.Cells(Sh.Rows.Count, 13).End(xlUp).Row + 1 '数据集M最后空白Row
- If [AD7] = "■" Then '服务类别
- ST = [AD7] '保固期
- Else
- ST = [AI7] '非保固期
- End If
- D1 = [C8] & "/" & [F8] & "/" & [I8] '制造日期
- D2 = [Q8] & "/" & [T8] & "/" & [W8] & Space(1) & Format([Y8], "00") & ":" & Format([AA8], "00") & " ~ " & [Q8] & "/" & [AD8] & "/" & [AF8] & Space(1) & Format([AH8], "00") & ":" & Format([AJ8], "00") '服务起止时间
- For i = 3 To 21 'C9~U9
- If Cells(9, i) = "■" Then
- SF = Cells(9, i + 1) '服务类型
- Exit For
- End If
- Next i
- If [AC9] = "■" Then '备件使用
- SP = [AD9] '免费提供
- Else
- SP = [AI9] '收费提供
- End If
- For i = 4 To 26 'D19~Z19
- If Cells(19, i) = "■" Then
- SR = Cells(19, i + 1) '服务工作结果
- Exit For
- End If
- Next i
- For i = 3 To 9 Step 2 'C21~I21
- If Cells(21, i) = "ν" Then
- SK = Cells(20, i) '服务技能
- Exit For
- End If
- Next i
- For i = 3 To 9 Step 2 'C22~I22
- If Cells(22, i) = "ν" Then
- SA = Cells(20, i) '服务态度
- Exit For
- End If
- Next i
- 'NO,单号,客户,地址,连络人/连系方式,项目名称,机台编号,服务类别,制造日期,服获3起止时间,服务类型,备件使用,故障现象,处理过程,改善建议,服务工作结果,其它,服务技能,服务态度,其它补充,客户签名,服务人员,服务时间
- Sh.Cells(r, 1).Resize(, 23) = Array(r - 4, [AB2], [B6], [R6], [AC6], [C7], [T7], ST, D1, D2, SF, SP, [E10], [E13], [E16], SR, [AC19], SK, SA, [M20], [AA21], [AG21], [AG22])
- a = MsgBox("存储已完成,是否要清除" & Me.Name & "内容?", vbInformation + vbYesNo)
- If a = vbYes Then
- Label1.Caption = "" '清除Label
- [C3,C4,AB2,E4,B6:N6,R6:V6,AC6:AK6,C7:O7,T7:Y7,C8:D8,F8:G8,I8,Q8:R8,T8:U8,W8,Y8,AA8,AD8,AF8,AH8,AJ8] = ""
- [E10:AK18,AC19:AK19,C21:I22,M20:Z22,AA21:AF22,AG21:AK21] = ""
- [AD7,AH7,C9,J9,K9,O9,R9,U9,AC9,AH9,D19,I19,O19,V19,Z19] = "□"
- End If
- CommandButton3.Enabled = False '隠藏"存储"按键
- Label1.Visible = False '隠藏Label1
- Set dic = CreateObject("scripting.dictionary")
- For i = 5 To Sh.Cells(Sh.Rows.Count, 1).End(xlUp).Row
- If Not dic.exists(Sh.Cells(i, 2).Value & "") Then dic.Add Sh.Cells(i, 2).Value, "" '查找不重复单号
- Next i
- With ComboBox1
- .Visible = True '显示ComboBox1
- .List = dic.keys '将不重复单号写入ComboBox1组合清单
- End With
- Set dic = Nothing
- End Sub
- Private Sub CommandButton4_Click() '打印
- Label1.Visible = False '隠藏Lable1
- ComboBox1.Visible = False '隠藏ComboBox1
- Application.Dialogs(xlDialogPrinterSetup).Show
- Me.PageSetup.PrintArea = Range("A1:AL24").Address
- With ActiveWindow.SelectedSheets
- .PrintPreview 'Preview工程服务单预览列印
- '.PrintOut Copies:=1 '打印,打印份数1
- End With
- ComboBox1.Visible = True '显示Combobox1
- End Sub
- Private Sub CommandButton5_Click() '查询修改
- Dim Sh As Worksheet, r As Long, dic As Object, i As Long
- Dim D1, D2, ST$, SF$, SP4, SK$, SR$, SA$
- Set Sh = Sheets("数据集")
- With Sh.Range("B3:B" & Sh.Cells(Sh.Rows.Count, 1).End(xlUp).Row)
- Set c = .Find(ComboBox1, LookIn:=xlValues, lookat:=xlWhole)
- If c Is Nothing Then
- MsgBox "找不到单号:" & [AB2], vbInformation + vbOKOnly
- Else
- If [Z19] = "■" And [AC19] = "" Then
- MsgBox [Z20] & [A19] & "不可空白", vbInformation + vbOKCancel
- [AC19].Select
- Exit Sub
- End If
- If [AG21] = "" Then
- MsgBox [AG20] & "不可空白", vbInformation + vbOKCancel
- [AG21].Select
- Exit Sub
- End If
- If [AG22] = "" Then
- MsgBox "AG22请填写服务时间", vbInformation + vbOKCancel
- [AG22].Select
- Exit Sub
- End If
- Set Sh = Sheets("数据集")
- r = Sh.Cells(Sh.Rows.Count, 13).End(xlUp).Row + 1 '数据集M最后空白Row
- If [AD7] = "■" Then '服务类别
- ST = [AD7] '保固期
- Else
- ST = [AI7] '非保固期
- End If
- D1 = [C8] & "/" & [F8] & "/" & [I8] '制造日期
- D2 = [Q8] & "/" & [T8] & "/" & [W8] & Space(1) & Format([Y8], "00") & ":" & Format([AA8], "00") & " ~ " & [Q8] & "/" & [AD8] & "/" & [AF8] & Space(1) & Format([AH8], "00") & ":" & Format([AJ8], "00") '服务起止时间
- For i = 3 To 21 'C9~U9
- If Cells(9, i) = "■" Then
- SF = Cells(9, i + 1) '服务类型
- Exit For
- End If
- Next i
- If [AC9] = "■" Then '备件使用
- SP = [AD9] '免费提供
- Else
- SP = [AI9] '收费提供
- End If
- For i = 4 To 26 'D19~Z19
- If Cells(19, i) = "■" Then
- SR = Cells(19, i + 1) '服务工作结果
- Exit For
- End If
- Next i
- For i = 3 To 9 Step 2 'C21~I21
- If Cells(21, i) = "ν" Then
- SK = Cells(20, i) '服务技能
- Exit For
- End If
- Next i
- For i = 3 To 9 Step 2 'C22~I22
- If Cells(22, i) = "ν" Then
- SA = Cells(20, i) '服务态度
- Exit For
- End If
- Next i
- 'NO,单号,客户,地址,连络人/连系方式,项目名称,机台编号,服务类别,制造日期,服获3起止时间,服务类型,备件使用,故障现象,处理过程,改善建议,服务工作结果,其它,服务技能,服务态度,其它补充,客户签名,服务人员,服务时间
- Sh.Cells(c.Row, 1).Resize(, 23) = Array(r - 4, [AB2], [B6], [R6], [AC6], [C7], [T7], ST, D1, D2, SF, SP, [E10], [E13], [E16], SR, [AC19], SK, SA, [M20], [AA21], [AG21], [AG22])
- a = MsgBox("存储已完成,是否要清除" & Me.Name & "内容?", vbInformation + vbYesNo)
- If a = vbYes Then
- Label1.Caption = ""
- [C3,C4,AB2,E4,B6:N6,R6:V6,AC6:AK6,C7:O7,T7:Y7,C8:D8,F8:G8,I8,Q8:R8,T8:U8,W8,Y8,AA8,AD8,AF8,AH8,AJ8] = ""
- [E10:AK18,AC19:AK19,C21:I22,M20:Z22,AA21:AF22,AG21:AK21] = ""
- [AD7,AH7,C9,J9,K9,O9,R9,U9,AC9,AH9,D19,I19,O19,V19,Z19] = "□"
- End If
- CommandButton3.Enabled = False
- Label1.Visible = False
- Set dic = CreateObject("scripting.dictionary")
- For i = 5 To Sh.Cells(Sh.Rows.Count, 1).End(xlUp).Row
- If Not dic.exists(Sh.Cells(i, 2).Value & "") Then dic.Add Sh.Cells(i, 2).Value, ""
- Next i
- With ComboBox1
- .Visible = True
- .List = dic.keys
- End With
- Set dic = Nothing
- End If
- End With
- End Sub
- Private Sub Worksheet_SelectionChange(ByVal Target As Range)
- If Target.Column = 17 And Target.Row > 7 And Target.Row < 12 Then
- Application.EnableEvents = False
- [q8:q11] = "↓"
- Target = "←"
- Application.EnableEvents = True
- End If
- End Sub
复制代码 |
|