ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 3027|回复: 19

[求助] 怎样做保存/打印/查询功能

[复制链接]

TA的精华主题

TA的得分主题

发表于 2012-12-5 20:30 | 显示全部楼层 |阅读模式
本帖最后由 gohao123 于 2012-12-5 20:53 编辑

各老师好!
我做了一个表单!请各位帮做一下功能!加上注释哦!我是新手!

怎样做保存/打印/查询功能


工程售后服务单 - 副本 (2).rar (105.21 KB, 下载次数: 32)


我试抄了一个!实现不了!!!


谢谢!


TA的精华主题

TA的得分主题

 楼主| 发表于 2012-12-6 08:47 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
还没老师过来看看。。。

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-12-6 09:21 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2012-12-6 16:03 | 显示全部楼层
本帖最后由 mineshine 于 2012-12-6 16:20 编辑
gohao123 发表于 2012-12-6 09:21
诚盼各位老师帮帮忙!!感谢了!!


我在繁体系统下写的
代码的中文如有乱码,请将代码复制黏贴。
ThisWorkBook里的代码:

  1. Private Sub Workbook_Open()
  2. Dim Sh As Worksheet
  3. Set Sh = Sheet4
  4.     Sheet1.Label1.Visible = False   '隠藏"工程服务单"Label1
  5.     Set dic = CreateObject("scripting.dictionary")
  6.     For i = 5 To Sh.Cells(Sh.Rows.Count, 1).End(xlUp).Row
  7.         If Not dic.exists(Sh.Cells(i, 2).Value & "") Then dic.Add Sh.Cells(i, 2).Value, ""  '查找不重复单号
  8.     Next i
  9.     With Sheet1.ComboBox1
  10.         .Visible = True     '显示"工程服务单"ComboBox1
  11.         .List = dic.keys    '将不重复单号写入ComboBox1组合清单
  12.     End With
  13.     Set dic = Nothing
  14. End Sub
复制代码

TA的精华主题

TA的得分主题

发表于 2012-12-6 16:04 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
"工程服務單"的TextBox我刪除了
改用 Label 和 ComboBox替代
"工程服務單"里的代码

  1. Private Sub CommandButton1_Click() '查询
  2.     Dim Sh As Worksheet, i As Long
  3.     Dim AB$, c As Object, fadd$, N
  4.     Set Sh = Sheets("数据集")
  5.     With Sh.Range("B3:B" & Sh.Cells(Sh.Rows.Count, 1).End(xlUp).Row)
  6.         Set c = .Find(ComboBox1, LookIn:=xlValues, lookat:=xlWhole)
  7.         If c Is Nothing Then
  8.             MsgBox "找不到单号:" & [AB2], vbInformation + vbOKOnly
  9.         Else
  10.             [AB2] = c '单号
  11.             [B6] = c.Offset(, 1) '客户
  12.             [R6] = c.Offset(, 2) '地址
  13.             [AC6] = c.Offset(, 3) '连络人/连糸方式
  14.             [C7] = c.Offset(, 4) '项目名称
  15.             [T7] = c.Offset(, 5) '机台编号
  16.             [C8] = Year(c.Offset(, 7)) '制造年
  17.             [F8] = Month(c.Offset(, 7)) '制造月
  18.             [I8] = Day(c.Offset(, 7)) '制造日
  19.             N = Split(c.Offset(, 8), " ~ ") '服务起止时间
  20.             [Q8] = Year(N(0))   '年
  21.             [T8] = Month(N(0))  '月
  22.             [W8] = Day(N(0))    '日
  23.             [Y8] = Hour(N(0))   '时
  24.             [AA8] = Minute(N(0))    '分
  25.             [AD8] = Month(N(1)) '月
  26.             [AF8] = Day(N(1))   '日
  27.             [AH8] = Hour(N(1))  '时
  28.             [AJ8] = Minute(N(1))    '分
  29.             [E10] = c.Offset(, 11) '故障现象
  30.             [E13] = c.Offset(, 12)  '处理过程
  31.             [E16] = c.Offset(, 13) '改善建议
  32.             [AC19] = c.Offset(, 15) '其它
  33.             [M20] = c.Offset(, 18) '其它補充
  34.             [AA21] = c.Offset(, 19) '客户签名
  35.             [AG21] = c.Offset(, 20) '服务人员
  36.             [AG22] = c.Offset(, 21) '服务时间
  37.             If c.Offset(, 6) = [AE7] Then   '服务类别
  38.                 [AD7] = "■"
  39.             Else
  40.                 [AH7] = "■"
  41.             End If
  42.             If c.Offset(, 10) = [AD9] Then   '备件使用
  43.                 [AC9] = "■"
  44.             Else
  45.                 [AH9] = "■"
  46.             End If
  47.             For i = 4 To 27
  48.                 If c.Offset(, 9) = Cells(9, i) Then Cells(9, i - 1) = "■"      '服务类型
  49.                 If c.Offset(, 14) = Cells(19, i) Then Cells(19, i - 1) = "■"   '服务工作结果
  50.             Next i
  51.             For i = 3 To 9 Step 2
  52.                 If c.Offset(, 16) = Cells(20, i) Then Cells(21, i) = "ν"   '服务技能
  53.                 If c.Offset(, 17) = Cells(20, i) Then Cells(22, i) = "ν"   '服务态度
  54.             Next i
  55.         End If
  56.     End With
  57. End Sub

  58. Private Sub CommandButton2_Click() '新单
  59.     Dim Sh As Worksheet
  60.     Dim AB$, c As Object, fadd$, NO
  61.     ComboBox1.Visible = False
  62.     Label1.Visible = True
  63.     Label1.Caption = "" '单号
  64.     [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] = ""
  65.     [E10:AK18,AC19:AK19,C21:I22,M20:Z22,AA21:AF22,AG21:AK21] = ""
  66.     [AD7,AH7,C9,J9,K9,O9,R9,U9,AC9,AH9,D19,I19,O19,V19,Z19] = "□"
  67.     Set Sh = Sheets("数据集")
  68.     AB = "JC" & Format(Date, "yyyymmdd")
  69.     With Sh.Range("B3:B" & Sh.Cells(Sh.Rows.Count, 1).End(xlUp).Row)
  70.         Set c = .Find(AB, LookIn:=xlValues, lookat:=xlPart)
  71.         If Not c Is Nothing Then
  72.             fadd = c.Address
  73.             Do
  74.                 If Right(c, 5) > NO Then NO = Right(c, 5)
  75.                 Set c = .FindNext(c)
  76.             Loop While Not c Is Nothing And c.Address <> fadd
  77.         Else
  78.             NO = ""
  79.         End If
  80.     End With
  81.     If NO = "" Then
  82.         Label1.Caption = "JC" & Format(Date, "yyyymmdd") & "00001"    '新单编号
  83.     Else
  84.         Label1.Caption = AB & Format(NO + 1, "00000")
  85.     End If
  86.     [AB2] = Label1.Caption  'AB2单号
  87.     CommandButton3.Enabled = True
  88. End Sub

  89. Private Sub CommandButton3_Click() '存储
  90.     Dim Sh As Worksheet, r As Long, dic As Object, i As Long
  91.     Dim D1, D2, ST$, SF$, SP4, SK$, SR$, SA$

  92.     If [Z19] = "■" And [AC19] = "" Then
  93.         MsgBox [Z20] & [A19] & "不可空白", vbInformation + vbOKCancel
  94.         [AC19].Select
  95.         Exit Sub
  96.     End If
  97.     If [AG21] = "" Then
  98.         MsgBox [AG20] & "不可空白", vbInformation + vbOKCancel
  99.         [AG21].Select
  100.         Exit Sub
  101.     End If
  102.     If [AG22] = "" Then
  103.         MsgBox "AG22请填写服务时间", vbInformation + vbOKCancel
  104.         [AG22].Select
  105.         Exit Sub
  106.     End If
  107.     Set Sh = Sheets("数据集")
  108.     r = Sh.Cells(Sh.Rows.Count, 13).End(xlUp).Row + 1    '数据集M最后空白Row
  109.     If [AD7] = "■" Then    '服务类别
  110.         ST = [AD7]  '保固期
  111.     Else
  112.         ST = [AI7]  '非保固期
  113.     End If
  114.     D1 = [C8] & "/" & [F8] & "/" & [I8] '制造日期
  115.     D2 = [Q8] & "/" & [T8] & "/" & [W8] & Space(1) & Format([Y8], "00") & ":" & Format([AA8], "00") & " ~ " & [Q8] & "/" & [AD8] & "/" & [AF8] & Space(1) & Format([AH8], "00") & ":" & Format([AJ8], "00") '服务起止时间
  116.     For i = 3 To 21 'C9~U9
  117.         If Cells(9, i) = "■" Then
  118.             SF = Cells(9, i + 1)    '服务类型
  119.             Exit For
  120.         End If
  121.     Next i
  122.     If [AC9] = "■" Then    '备件使用
  123.         SP = [AD9]  '免费提供
  124.     Else
  125.         SP = [AI9]  '收费提供
  126.     End If
  127.     For i = 4 To 26 'D19~Z19
  128.         If Cells(19, i) = "■" Then
  129.             SR = Cells(19, i + 1)    '服务工作结果
  130.             Exit For
  131.         End If
  132.     Next i
  133.     For i = 3 To 9 Step 2 'C21~I21
  134.         If Cells(21, i) = "ν" Then
  135.             SK = Cells(20, i)     '服务技能
  136.             Exit For
  137.         End If
  138.     Next i
  139.     For i = 3 To 9 Step 2 'C22~I22
  140.         If Cells(22, i) = "ν" Then
  141.             SA = Cells(20, i)    '服务态度
  142.             Exit For
  143.         End If
  144.     Next i
  145.     'NO,单号,客户,地址,连络人/连系方式,项目名称,机台编号,服务类别,制造日期,服获3起止时间,服务类型,备件使用,故障现象,处理过程,改善建议,服务工作结果,其它,服务技能,服务态度,其它补充,客户签名,服务人员,服务时间
  146.     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])
  147.     a = MsgBox("存储已完成,是否要清除" & Me.Name & "内容?", vbInformation + vbYesNo)
  148.     If a = vbYes Then
  149.         Label1.Caption = "" '清除Label
  150.         [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] = ""
  151.         [E10:AK18,AC19:AK19,C21:I22,M20:Z22,AA21:AF22,AG21:AK21] = ""
  152.         [AD7,AH7,C9,J9,K9,O9,R9,U9,AC9,AH9,D19,I19,O19,V19,Z19] = "□"
  153.     End If
  154.     CommandButton3.Enabled = False      '隠藏"存储"按键
  155.     Label1.Visible = False              '隠藏Label1
  156.     Set dic = CreateObject("scripting.dictionary")
  157.     For i = 5 To Sh.Cells(Sh.Rows.Count, 1).End(xlUp).Row
  158.         If Not dic.exists(Sh.Cells(i, 2).Value & "") Then dic.Add Sh.Cells(i, 2).Value, ""  '查找不重复单号
  159.     Next i
  160.     With ComboBox1
  161.         .Visible = True     '显示ComboBox1
  162.         .List = dic.keys    '将不重复单号写入ComboBox1组合清单
  163.     End With
  164.     Set dic = Nothing
  165. End Sub

  166. Private Sub CommandButton4_Click() '打印
  167. Label1.Visible = False      '隠藏Lable1
  168. ComboBox1.Visible = False   '隠藏ComboBox1
  169. Application.Dialogs(xlDialogPrinterSetup).Show
  170. Me.PageSetup.PrintArea = Range("A1:AL24").Address
  171. With ActiveWindow.SelectedSheets
  172.     .PrintPreview               'Preview工程服务单预览列印
  173.     '.PrintOut Copies:=1 '打印,打印份数1
  174. End With
  175. ComboBox1.Visible = True    '显示Combobox1
  176. End Sub

  177. Private Sub CommandButton5_Click()  '查询修改
  178.     Dim Sh As Worksheet, r As Long, dic As Object, i As Long
  179.     Dim D1, D2, ST$, SF$, SP4, SK$, SR$, SA$
  180.     Set Sh = Sheets("数据集")
  181.     With Sh.Range("B3:B" & Sh.Cells(Sh.Rows.Count, 1).End(xlUp).Row)
  182.         Set c = .Find(ComboBox1, LookIn:=xlValues, lookat:=xlWhole)
  183.         If c Is Nothing Then
  184.             MsgBox "找不到单号:" & [AB2], vbInformation + vbOKOnly
  185.         Else
  186.             If [Z19] = "■" And [AC19] = "" Then
  187.                 MsgBox [Z20] & [A19] & "不可空白", vbInformation + vbOKCancel
  188.                 [AC19].Select
  189.                 Exit Sub
  190.             End If
  191.             If [AG21] = "" Then
  192.                 MsgBox [AG20] & "不可空白", vbInformation + vbOKCancel
  193.                 [AG21].Select
  194.                 Exit Sub
  195.             End If
  196.             If [AG22] = "" Then
  197.                 MsgBox "AG22请填写服务时间", vbInformation + vbOKCancel
  198.                 [AG22].Select
  199.                 Exit Sub
  200.             End If
  201.             Set Sh = Sheets("数据集")
  202.             r = Sh.Cells(Sh.Rows.Count, 13).End(xlUp).Row + 1    '数据集M最后空白Row
  203.             If [AD7] = "■" Then    '服务类别
  204.                 ST = [AD7]  '保固期
  205.             Else
  206.                 ST = [AI7]  '非保固期
  207.             End If
  208.             D1 = [C8] & "/" & [F8] & "/" & [I8] '制造日期
  209.             D2 = [Q8] & "/" & [T8] & "/" & [W8] & Space(1) & Format([Y8], "00") & ":" & Format([AA8], "00") & " ~ " & [Q8] & "/" & [AD8] & "/" & [AF8] & Space(1) & Format([AH8], "00") & ":" & Format([AJ8], "00") '服务起止时间
  210.             For i = 3 To 21 'C9~U9
  211.                 If Cells(9, i) = "■" Then
  212.                     SF = Cells(9, i + 1)    '服务类型
  213.                     Exit For
  214.                 End If
  215.             Next i
  216.             If [AC9] = "■" Then    '备件使用
  217.                 SP = [AD9]  '免费提供
  218.             Else
  219.                 SP = [AI9]  '收费提供
  220.             End If
  221.             For i = 4 To 26 'D19~Z19
  222.                 If Cells(19, i) = "■" Then
  223.                     SR = Cells(19, i + 1)    '服务工作结果
  224.                     Exit For
  225.                 End If
  226.             Next i
  227.             For i = 3 To 9 Step 2 'C21~I21
  228.                 If Cells(21, i) = "ν" Then
  229.                     SK = Cells(20, i)     '服务技能
  230.                     Exit For
  231.                 End If
  232.             Next i
  233.             For i = 3 To 9 Step 2 'C22~I22
  234.                 If Cells(22, i) = "ν" Then
  235.                     SA = Cells(20, i)    '服务态度
  236.                     Exit For
  237.                 End If
  238.             Next i
  239.             'NO,单号,客户,地址,连络人/连系方式,项目名称,机台编号,服务类别,制造日期,服获3起止时间,服务类型,备件使用,故障现象,处理过程,改善建议,服务工作结果,其它,服务技能,服务态度,其它补充,客户签名,服务人员,服务时间
  240.             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])
  241.             a = MsgBox("存储已完成,是否要清除" & Me.Name & "内容?", vbInformation + vbYesNo)
  242.             If a = vbYes Then
  243.                 Label1.Caption = ""
  244.                 [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] = ""
  245.                 [E10:AK18,AC19:AK19,C21:I22,M20:Z22,AA21:AF22,AG21:AK21] = ""
  246.                 [AD7,AH7,C9,J9,K9,O9,R9,U9,AC9,AH9,D19,I19,O19,V19,Z19] = "□"
  247.             End If
  248.             CommandButton3.Enabled = False
  249.             Label1.Visible = False
  250.             Set dic = CreateObject("scripting.dictionary")
  251.             For i = 5 To Sh.Cells(Sh.Rows.Count, 1).End(xlUp).Row
  252.                 If Not dic.exists(Sh.Cells(i, 2).Value & "") Then dic.Add Sh.Cells(i, 2).Value, ""
  253.             Next i
  254.             With ComboBox1
  255.                 .Visible = True
  256.                 .List = dic.keys
  257.             End With
  258.             Set dic = Nothing
  259.         End If
  260.     End With
  261. End Sub

  262. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  263.     If Target.Column = 17 And Target.Row > 7 And Target.Row < 12 Then
  264.         Application.EnableEvents = False
  265.         [q8:q11] = "↓"
  266.         Target = "←"
  267.         Application.EnableEvents = True
  268.     End If
  269. End Sub
复制代码

TA的精华主题

TA的得分主题

发表于 2012-12-6 16:06 | 显示全部楼层
本帖最后由 mineshine 于 2012-12-6 16:07 编辑

我在繁体系统下写的
代码的中文如有乱码,请将代码复制黏贴。

参见附件

工程售后服务单 20121206-1.rar

115.35 KB, 下载次数: 36

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-12-6 21:57 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
本帖最后由 gohao123 于 2012-12-6 22:08 编辑

谢谢楼上老师指点!功能不错!注释也很详细!但还有一点改动一下!附件中!有说明了!谢谢!

工程售后服务单 20121206-2.rar (134.79 KB, 下载次数: 19)

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-12-7 09:07 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2012-12-7 15:52 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
gohao123 发表于 2012-12-6 21:57
谢谢楼上老师指点!功能不错!注释也很详细!但还有一点改动一下!附件中!有说明了!谢谢!

ThisWorkBook里的代码:

  1. Private Sub Workbook_Open()
  2. Dim Sh As Worksheet
  3. Application.ScreenUpdating = False
  4. Set Sh = Sheets("数据集")
  5.     Sheet1.Label1.Visible = False   '隠藏"工程服务单"Label1
  6.     Set dic = CreateObject("scripting.dictionary")
  7.     For i = 5 To Sh.Cells(Sh.Rows.Count, 1).End(xlUp).Row
  8.         If Not dic.exists(Sh.Cells(i, 2).Value & "") Then dic.Add Sh.Cells(i, 2).Value, ""  '查找不重复单号
  9.     Next i
  10.     With Sheet1.ComboBox1   '单号
  11.         .Value = ""
  12.         .Visible = True     '显示"工程服务单"ComboBox1
  13.         .List = dic.keys    '将不重复单号写入ComboBox1组合清单
  14.     End With
  15.     Set dic = Nothing
  16.     Sheet1.Protect        '工作表保护
  17. Application.ScreenUpdating = True
  18. End Sub
复制代码

TA的精华主题

TA的得分主题

发表于 2012-12-7 15:52 | 显示全部楼层
"工程服務單"代码
  1. Private Sub CommandButton1_Click() '查询
  2.     Dim Sh As Worksheet, i As Long
  3.     Dim AB$, c As Object, fadd$, N
  4.     Application.ScreenUpdating = False
  5.     ClearCells    '执行ClearCells清除栏位
  6.     Me.Unprotect    '取消工作表保护
  7.     ComboBox1.Visible = True
  8.     Label1.Visible = False
  9.     Set Sh = Sheets("数据集")
  10.     With Sh.Range("B3:B" & Sh.Cells(Sh.Rows.Count, 1).End(xlUp).Row)
  11.         Set c = .Find(ComboBox1, LookIn:=xlValues, lookat:=xlWhole)
  12.         If c Is Nothing Then
  13.             MsgBox "找不到单号:" & [AB2], vbInformation + vbOKOnly
  14.         Else
  15.             [AB2] = c '单号
  16.             [B6] = c.Offset(, 1)            '客户
  17.             [R6] = c.Offset(, 2)            '地址
  18.             [AC6] = c.Offset(, 3)           '连络人/连络方式
  19.             [C7] = c.Offset(, 4)            '项目名称
  20.             [T7] = c.Offset(, 5)            '机台编号
  21.             [C8] = Year(c.Offset(, 7))      '制造年
  22.             [F8] = Month(c.Offset(, 7))     '制造月
  23.             [I8] = Day(c.Offset(, 7))       '制造日
  24.             N = Split(c.Offset(, 8), " ~ ") '分割服务起止时间
  25.             [Q8] = Year(N(0))       '起年
  26.             [T8] = Month(N(0))      '起月
  27.             [W8] = Day(N(0))        '起日
  28.             [Y8] = Hour(N(0))       '起时
  29.             [AA8] = Minute(N(0))    '起分
  30.             [AD8] = Month(N(1))     '止月
  31.             [AF8] = Day(N(1))       '止日
  32.             [AH8] = Hour(N(1))      '止时
  33.             [AJ8] = Minute(N(1))    '止分
  34.             [E10] = c.Offset(, 11) '故障现象
  35.             [E13] = c.Offset(, 12)  '处理过程
  36.             [E16] = c.Offset(, 13) '改善建议
  37.             [AC19] = c.Offset(, 15) '其它
  38.             [M20] = c.Offset(, 18) '其它補充
  39.             [AA21] = c.Offset(, 19) '客户签名
  40.             [AG21] = c.Offset(, 20) '服务人员
  41.             [AG22] = c.Offset(, 21) '服务时间
  42.             If c.Offset(, 6) = [AE7] Then   '服务类别
  43.                 [AD7] = "■"
  44.             Else
  45.                 [AH7] = "■"
  46.             End If
  47.             If c.Offset(, 10) = [AD9] Then   '备件使用
  48.                 [AC9] = "■"
  49.             Else
  50.                 [AH9] = "■"
  51.             End If
  52.             For i = 4 To 27
  53.                 If i = 4 Or i = 8 Or i = 12 Or i = 16 Or i = 19 Or i = 22 Then
  54.                     If c.Offset(, 9) = Cells(9, i) Then Cells(9, i - 1) = "■"      '服务类型
  55.                 ElseIf i = 5 Or i = 10 Or i = 16 Or i = 23 Or i = 27 Then
  56.                     If c.Offset(, 14) = Cells(19, i) Then Cells(19, i - 1) = "■"   '服务工作结果
  57.                 End If
  58.             Next i
  59.             For i = 3 To 9 Step 2
  60.                 If c.Offset(, 16) = Cells(20, i) Then Cells(21, i) = "ν"   '服务技能
  61.                 If c.Offset(, 17) = Cells(20, i) Then Cells(22, i) = "ν"   '服务态度
  62.             Next i
  63.         End If
  64.     End With
  65.     Me.Protect        '工作表保护
  66. Application.ScreenUpdating = True
  67. End Sub

  68. Private Sub CommandButton2_Click() '新单
  69.     Dim Sh As Worksheet
  70.     Dim AB$, c As Object, fadd$, NO
  71.     ComboBox1.Visible = False
  72.     Label1.Visible = True
  73.     ClearCells    '执行ClearCells清除栏位
  74.     Set Sh = Sheets("数据集")
  75.     AB = "JC" & Format(Date, "yyyymmdd")
  76.     With Sh.Range("B3:B" & Sh.Cells(Sh.Rows.Count, 1).End(xlUp).Row)
  77.         Set c = .Find(AB, LookIn:=xlValues, lookat:=xlPart)
  78.         If Not c Is Nothing Then
  79.             fadd = c.Address
  80.             Do
  81.                 If Right(c, 5) > NO Then NO = Right(c, 5)
  82.                 Set c = .FindNext(c)
  83.             Loop While Not c Is Nothing And c.Address <> fadd
  84.         Else
  85.             NO = ""
  86.         End If
  87.     End With
  88.     If NO = "" Then
  89.         Label1.Caption = "JC" & Format(Date, "yyyymmdd") & "00001"    '新单编号
  90.     Else
  91.         Label1.Caption = AB & Format(NO + 1, "00000")
  92.     End If
  93.     Me.Unprotect    '取消工作表保护
  94.     [AB2] = Label1.Caption  'AB2单号
  95.     CommandButton3.Enabled = True
  96. End Sub

  97. Private Sub CommandButton3_Click() '存储
  98.     Dim Sh As Worksheet, r As Long, dic As Object, i As Long
  99.     Dim D1, D2, ST$, SF$, SP4, SK$, SR$, SA$
  100.     If [Z19] = "■" And [AC19] = "" Then     '服务工作结果:其他
  101.         MsgBox [Z20] & [A19] & "不可空白", vbInformation + vbOKCancel
  102.         [AC19].Select
  103.         Exit Sub
  104.     ElseIf [AC19] <> "" Then
  105.         [Z19] = "■"
  106.         For i = 4 To 22
  107.             If i = 4 Or i = 9 Or i = 15 Or i = 22 Then Cells(19, i) = "□"
  108.         Next i
  109.     End If
  110.     If [AG21] = "" Then
  111.         MsgBox [AG20] & "不可空白", vbInformation + vbOKCancel
  112.         [AG21].Select
  113.         Exit Sub
  114.     End If
  115.     If [AG22] = "" Then
  116.         MsgBox "AG22请填写服务时间", vbInformation + vbOKCancel
  117.         [AG22].Select
  118.         Exit Sub
  119.     End If
  120.     Set Sh = Sheets("数据集")
  121.     r = Sh.Cells(Sh.Rows.Count, 13).End(xlUp).Row + 1    '数据集M最后空白Row
  122.     If [AD7] = "■" Then    '服务类别
  123.         ST = [AE7]  '保固期
  124.     Else
  125.         ST = [AI7]  '非保固期
  126.     End If
  127.     D1 = [C8] & "/" & [F8] & "/" & [I8] '制造日期
  128.     D2 = Format([Q8], "0000") & "/" & Format([T8], "00") & "/" & Format([W8], "00") & Space(1) & Format([Y8], "00") & ":" & Format([AA8], "00") & _
  129.          " ~ " & Format([Q8], "0000") & "/" & Format([AD8], "00") & "/" & Format([AF8], "00") & Space(1) & Format([AH8], "00") & ":" & Format([AJ8], "00") '服务起止时间
  130.     For i = 3 To 21 'C9~U9
  131.         If Cells(9, i) = "■" Then
  132.             SF = Cells(9, i + 1)    '服务类型
  133.             Exit For
  134.         End If
  135.     Next i
  136.     If [AC9] = "■" Then    '备件使用
  137.         SP = [AD9]  '免费提供
  138.     Else
  139.         SP = [AI9]  '收费提供
  140.     End If
  141.     For i = 4 To 26 'D19~Z19
  142.         If Cells(19, i) = "■" Then
  143.             SR = Cells(19, i + 1)    '服务工作结果
  144.             Exit For
  145.         End If
  146.     Next i
  147.     For i = 3 To 9 Step 2 'C21~I21
  148.         If Cells(21, i) = "ν" Then
  149.             SK = Cells(20, i)     '服务技能
  150.             Exit For
  151.         End If
  152.     Next i
  153.     For i = 3 To 9 Step 2 'C22~I22
  154.         If Cells(22, i) = "ν" Then
  155.             SA = Cells(20, i)    '服务态度
  156.             Exit For
  157.         End If
  158.     Next i
  159.     With Sh.Range("B3:B" & Sh.Cells(Sh.Rows.Count, 1).End(xlUp).Row)
  160.         Set c = .Find(ComboBox1, LookIn:=xlValues, lookat:=xlWhole)
  161.         If c Is Nothing Then
  162.             'NO,单号,客户,地址,连络人/连系方式,项目名称,机台编号,服务类别,制造日期,服务起止时间,服务类型,备件使用,故障现象,处理过程,改善建议,服务工作结果,其它,服务技能,服务态度,其它补充,客户签名,服务人员,服务时间
  163.             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])
  164.         Else
  165.             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])
  166.         End If
  167.     End With
  168.     a = MsgBox("存储已完成,是否要清除" & Me.Name & "内容?", vbInformation + vbYesNo)
  169.     If a = vbYes Then ClearCells    '执行ClearCells清除栏位
  170.     CommandButton3.Enabled = False      '隠藏"存储"按键
  171.     Label1.Visible = False              '隠藏Label1
  172.     Set dic = CreateObject("scripting.dictionary")
  173.     For i = 5 To Sh.Cells(Sh.Rows.Count, 1).End(xlUp).Row
  174.         If Not dic.exists(Sh.Cells(i, 2).Value & "") Then dic.Add Sh.Cells(i, 2).Value, ""  '查找不重复单号
  175.     Next i
  176.     With ComboBox1
  177.         .Visible = True     '显示ComboBox1
  178.         .List = dic.keys    '将不重复单号写入ComboBox1组合清单
  179.     End With
  180.     Set dic = Nothing
  181.     Me.Protect        '工作表保护
  182. End Sub

  183. Private Sub CommandButton4_Click() '打印
  184. Label1.Visible = False      '隠藏Lable1
  185. ComboBox1.Visible = False   '隠藏ComboBox1
  186. Application.Dialogs(xlDialogPrinterSetup).Show
  187. Me.PageSetup.PrintArea = Range("A1:AL24").Address   '打印范围
  188. With ActiveWindow.SelectedSheets
  189.     .PrintPreview               'Preview工程服务单预览列印
  190.     '.PrintOut Copies:=1 '打印,打印份数1
  191. End With
  192. ComboBox1.Visible = True    '显示Combobox1
  193. End Sub

  194. Private Sub CommandButton5_Click()  '查询修改
  195.     Dim Sh As Worksheet, r As Long, dic As Object, i As Long
  196.     Dim D1, D2, ST$, SF$, SP4, SK$, SR$, SA$
  197.     CommandButton3.Enabled = True    '"存储"按键激活
  198.     Me.Unprotect  '取消工作表保护
  199. End Sub

  200. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  201. Dim Rng$, i%
  202.     If Me.ProtectContents = True Then
  203.         [C8,Q8,F8,T8,AD8,I8,W8,AF8,Y8,AH8,AA8,AJ8].Validation.Delete
  204.         Exit Sub    '如果工作表视窗处于保护状态就不执行触发事件
  205.     Else
  206.         If CommandButton3.Enabled = True Then  '当"存储"按键可用时
  207.             Rng = ""
  208.             If Target.Row = 8 Then  '制造日期, 服务起止时间
  209.                 If Target.Address = "$C$8:$D$8" Or Target.Address = "$Q$8:$R$8" Then
  210.                     For i = Year(Date) To Year(Date) + 10   '年
  211.                         Rng = Rng & "," & i
  212.                     Next i
  213.                 ElseIf Target.Address = "$F$8:$G$8" Or Target.Address = "$T$8:$U$8" Or Target.Address = "$AD$8" Then
  214.                     For i = 1 To 12     '月
  215.                         Rng = Rng & "," & i
  216.                     Next i
  217.                 ElseIf Target.Address = "$I$8" Or Target.Address = "$W$8" Or Target.Address = "$AF$8" Then
  218.                     D = Day(DateSerial(Target.Offset(, -6), Target.Offset(, -3) + 1, 1) - 1)
  219.                     For i = 1 To D     '日
  220.                         Rng = Rng & "," & i
  221.                     Next i
  222.                 ElseIf Target.Address = "$Y$8" Or Target.Address = "$AH$8" Then
  223.                     For i = 0 To 23     '时
  224.                         Rng = Rng & "," & i
  225.                     Next i
  226.                 ElseIf Target.Address = "$AA$8" Or Target.Address = "$AJ$8" Then
  227.                     For i = 0 To 59     '分
  228.                         Rng = Rng & "," & i
  229.                     Next i
  230.                 End If
  231.                 Rng = Mid(Rng, 2)
  232.                 Target.Validation.Delete
  233.                 Target.Validation.Add 3, 1, 1, Rng '数据有效性
  234.             End If
  235.             If Target.Address = "$AD$7" Or Target.Address = "$AH$7" Then    '服务类别
  236.                 If [AD7] = "□" Then
  237.                     [AD7] = "■"    '保固期
  238.                     [AH7] = "□"    '非保固期
  239.                 Else
  240.                     [AD7] = "□"    '保固期
  241.                     [AH7] = "■"    '非保固期
  242.                 End If
  243.             End If
  244.             If Target.Address = "$AC$9" Or Target.Address = "$AH$9" Then    '备件使用
  245.                 If [AC9] = "□" Then
  246.                     [AC9] = "■"    '免费提供
  247.                     [AH9] = "□"    '收费提供
  248.                 Else
  249.                     [AC9] = "□"    '免费提供
  250.                     [AH9] = "■"    '收费提供
  251.                 End If
  252.             End If
  253.             If Target.Row = 9 And (Target.Column = 3 Or Target.Column = 7 Or Target.Column = 11 Or Target.Column = 15 Or Target.Column = 18 Or Target.Column = 21) Then '服务类型
  254.                 If Target = "□" Then
  255.                     Target = "■"
  256.                     t = Target.Column
  257.                 Else
  258.                     Target = "□"
  259.                     Exit Sub
  260.                 End If
  261.                 For i = 3 To 21 'C9,G9,K9,O9,,R9,U9
  262.                     If i = 3 Or i = 7 Or i = 11 Or i = 15 Or i = 18 Or i = 21 Then If i <> t And Cells(9, i) = "■" Then Cells(9, i) = "□"
  263.                 Next i
  264.             End If
  265.             If Target.Row = 19 And (Target.Column = 4 Or Target.Column = 9 Or Target.Column = 15 Or Target.Column = 18 Or Target.Column = 22 Or Target.Column = 26) Then '服务工作结果
  266.                 If Target = "□" Then
  267.                     Target = "■"
  268.                     t = Target.Column
  269.                 Else
  270.                     Target = "□"
  271.                     Exit Sub
  272.                 End If
  273.                 If Target.Address <> "$Z$19" Then [AC19] = ""   '选择非"其它",[AC19]清空
  274.                 For i = 4 To 26 'D19,I19,O1,V19,,Z19
  275.                     If i = 4 Or i = 9 Or i = 15 Or i = 18 Or i = 22 Or i = 26 Then If i <> t And Cells(19, i) = "■" Then Cells(19, i) = "□"
  276.                 Next i
  277.             End If
  278.             If Target.Row = 21 Or Target.Row = 22 And (Target.Column > 2 And Target.Column < 10) Then '客户评价
  279.                 If Cells(Target.Row, Target.Column) = "ν" Then
  280.                     'Target = "ν"
  281.                     t = Target.Column
  282.                 Else
  283.                     Target = "ν"
  284.                     t = Target.Column
  285.                 End If
  286.                 For i = 3 To 9 Step 2
  287.                     If i <> t And Cells(Target.Row, i) = "ν" Then Cells(Target.Row, i) = ""
  288.                 Next i
  289.             End If
  290.         Else
  291.             [C8,Q8,F8,T8,AD8,I8,W8,AF8,Y8,AH8,AA8,AJ8].Validation.Delete
  292.         End If
  293.     End If
  294. End Sub

  295. Sub ClearCells()
  296.     With Sheet1
  297.         .Unprotect
  298.         .Label1.Caption = "" '清除Label
  299.         .[AB2:AK2,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] = ""
  300.         .[E10:AK18,AC19:AK19,C21:I22,M20:Z22,AA21:AF22,AG21:AK21,AG22:AK22] = ""
  301.         .[AD7,AH7,C9,G9,K9,O9,R9,U9,AC9,AH9,D19,I19,O19,V19,Z19] = "□"
  302.     End With
  303. End Sub
复制代码

评分

1

查看全部评分

您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

关闭

最新热点上一条 /1 下一条

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-4-25 16:34 , Processed in 0.042411 second(s), 16 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表