1234

ExcelHome技术论坛

用户名  找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

帖子
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
12
返回列表 发新帖
楼主: gohao123

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

[复制链接]

TA的精华主题

TA的得分主题

发表于 2012-12-7 15:55 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
製造日期、服務起止時間  单元格改用数据有效性

如果你还要再更改模板
我的代码注解很详细
你可以自行修改

工程售后服务单 20121207.rar

130.38 KB, 下载次数: 32

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-12-7 17:02 | 显示全部楼层
谢谢!{:soso_e179:}

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-12-7 20:00 | 显示全部楼层
还有几个小问题:
1。第一次或新打开--新单--存储时会覆盖前一单号                               
2。新单时AF8没可选择日期                               
3。C21点V时不保存服务技能“好”        21行点击也会出现“V”                       
4。AA21、AG21点击时会出现“V”本是不要的                               
5。数据NO没从1号开始                               
6。查询时没法修改!保护了                               

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-12-7 20:02 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
{:soso_e110:}不好意思!我是刚学的!(一点也还会的)

TA的精华主题

TA的得分主题

发表于 2012-12-10 09:50 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
gohao123 发表于 2012-12-7 20:00
还有几个小问题:
1。第一次或新打开--新单--存储时会覆盖前一单号                               
2。新单时AF8没可选择日期                               

1-5、"工程服務單" 代码修改如下
6、修改查询单:按"查询"查询服務单→按"查询修改"修改服务单
  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.             r = Sh.Cells(Sh.Rows.Count, 2).End(xlUp).Row + 1  '数据集最后空白Row
  163.             'NO,单号,客户,地址,连络人/连系方式,项目名称,机台编号,服务类别,制造日期,服务起止时间,服务类型,备件使用,故障现象,处理过程,改善建议,服务工作结果,其它,服务技能,服务态度,其它补充,客户签名,服务人员,服务时间
  164.             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])
  165.         Else
  166.             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])
  167.         End If
  168.     End With
  169.     a = MsgBox("存储已完成,是否要清除" & Me.Name & "内容?", vbInformation + vbYesNo)
  170.     If a = vbYes Then ClearCells    '执行ClearCells清除栏位
  171.     CommandButton3.Enabled = False      '隠藏"存储"按键
  172.     Label1.Visible = False              '隠藏Label1
  173.     Set dic = CreateObject("scripting.dictionary")
  174.     For i = 5 To Sh.Cells(Sh.Rows.Count, 1).End(xlUp).Row
  175.         If Not dic.exists(Sh.Cells(i, 2).Value & "") Then dic.Add Sh.Cells(i, 2).Value, ""  '查找不重复单号
  176.     Next i
  177.     With ComboBox1
  178.         .Visible = True     '显示ComboBox1
  179.         .List = dic.keys    '将不重复单号写入ComboBox1组合清单
  180.     End With
  181.     Set dic = Nothing
  182.     Me.Protect        '工作表保护
  183. End Sub

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

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

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

  307. Sub ClearCells()
  308.     With Sheet1
  309.         .Unprotect
  310.         .Label1.Caption = "" '清除Label
  311.         .[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] = ""
  312.         .[E10:AK18,AC19:AK19,C21:I22,M20:Z22,AA21:AF22,AG21:AK21,AG22:AK22] = ""
  313.         .[AD7,AH7,C9,G9,K9,O9,R9,U9,AC9,AH9,D19,I19,O19,V19,Z19] = "□"
  314.     End With
  315. End Sub
复制代码

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-12-10 10:21 | 显示全部楼层
保行数出错!现保存到行4了!因行3和行4有合并了!应从行5开始!!

TA的精华主题

TA的得分主题

发表于 2012-12-10 11:11 | 显示全部楼层
gohao123 发表于 2012-12-10 10:21
保行数出错!现保存到行4了!因行3和行4有合并了!应从行5开始!!

  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, 13).End(xlUp).Row)
  160.         Set c = .Find(ComboBox1, LookIn:=xlValues, lookat:=xlWhole)
  161.         If c Is Nothing Then
  162.             r = Sh.Cells(Sh.Rows.Count, 13).End(xlUp).Row + 1  '数据集最后空白Row
  163.             'NO,单号,客户,地址,连络人/连系方式,项目名称,机台编号,服务类别,制造日期,服务起止时间,服务类型,备件使用,故障现象,处理过程,改善建议,服务工作结果,其它,服务技能,服务态度,其它补充,客户签名,服务人员,服务时间
  164.             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])
  165.         Else
  166.             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])
  167.         End If
  168.     End With
  169.     a = MsgBox("存储已完成,是否要清除" & Me.Name & "内容?", vbInformation + vbYesNo)
  170.     If a = vbYes Then ClearCells    '执行ClearCells清除栏位
  171.     CommandButton3.Enabled = False      '隠藏"存储"按键
  172.     Label1.Visible = False              '隠藏Label1
  173.     Set dic = CreateObject("scripting.dictionary")
  174.     For i = 5 To Sh.Cells(Sh.Rows.Count, 1).End(xlUp).Row
  175.         If Not dic.exists(Sh.Cells(i, 2).Value & "") Then dic.Add Sh.Cells(i, 2).Value, ""  '查找不重复单号
  176.     Next i
  177.     With ComboBox1
  178.         .Visible = True     '显示ComboBox1
  179.         .List = dic.keys    '将不重复单号写入ComboBox1组合清单
  180.     End With
  181.     Set dic = Nothing
  182.     Me.Protect        '工作表保护
  183. End Sub

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

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

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

  307. Sub ClearCells()
  308.     With Sheet1
  309.         .Unprotect
  310.         .Label1.Caption = "" '清除Label
  311.         .[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] = ""
  312.         .[E10:AK18,AC19:AK19,C21:I22,M20:Z22,AA21:AF22,AG21:AK21,AG22:AK22] = ""
  313.         .[AD7,AH7,C9,G9,K9,O9,R9,U9,AC9,AH9,D19,I19,O19,V19,Z19] = "□"
  314.     End With
  315. End Sub
复制代码

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-12-10 13:43 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
又要修改动了!附件中!

工程售后服务单 20121210.rar

123.81 KB, 下载次数: 14

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-12-14 18:52 | 显示全部楼层

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-12-18 22:09 | 显示全部楼层
再更新了一下!烦各高手帮处理一下!谢谢!!

工程售后服务单测试版20121218B.rar

107.23 KB, 下载次数: 13

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

本版积分规则

1234

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

GMT+8, 2025-4-21 06:15 , Processed in 0.039400 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

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

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

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