Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1839|回复: 6

[已解决]如何更改以下代码

[复制链接]
发表于 2011-11-8 21:28 | 显示全部楼层 |阅读模式
以下标红色的是我想要定义实现的,首先我不想定义成sheets(表名)这样的类型,我只想要前面部分的名称,比如在vbe窗口看到如下的表名sheet9(一线)我只想要前面的sheet9,请高手帮忙解决一下,谢谢了
Private Sub CommandButton1_Click()
Dim i As Integer
Dim j As Integer
If TextBox3.Value = "" Then
MsgBox "厚度不能为空!!"
ElseIf TextBox4.Value = "" Then
MsgBox "长度不能为空!!"
ElseIf TextBox5.Value = "" Then
MsgBox "宽度不能为空!!"
ElseIf TextBox6.Value = "" Then
MsgBox "片数不能为空!!"
ElseIf ComboBox1.Value = "" Then
MsgBox "请选择包装方式!!"
ElseIf TextBox16.Value = "" Then
MsgBox "批次不能为空!!无批次请输入0!"
ElseIf 班组选择.ComboBox1.Value = "第一生产线" Then
one
ElseIf 班组选择.ComboBox1.Value = "第二生产线" Then
two
ElseIf 班组选择.ComboBox1.Value = "第三生产线" And 班组选择.ComboBox4.Value = "普通白玻" Then
i = 9
ElseIf 班组选择.ComboBox1.Value = "第三生产线" And 班组选择.ComboBox4.Value = "超白玻璃" Then
i = 8
ElseIf 班组选择.ComboBox1.Value = "第四生产线" And 班组选择.ComboBox4.Value = "普通白玻" Then
i = 7
End If
If TextBox7.Text = "" Then TextBox7.Text = 0
If TextBox8.Text = "" Then TextBox8.Text = 0
If TextBox9.Text = "" Then TextBox9.Text = 0
If TextBox10.Text = "" Then TextBox10.Text = 0
If TextBox11.Text = "" Then TextBox11.Text = 0
If TextBox12.Text = "" Then TextBox12.Text = 0
If TextBox13.Text = "" Then TextBox13.Text = 无
Sheet(i).Range("A65536").End(xlUp).Offset(1) = TextBox14.Text
Sheet(i).Range("B65536").End(xlUp).Offset(1) = TextBox1.Text
Sheet(i).Range("C65536").End(xlUp).Offset(1) = TextBox2.Text
Sheet(i).Range("D65536").End(xlUp).Offset(1) = TextBox3.Value
Sheet(i).Range("E65536").End(xlUp).Offset(1) = TextBox4.Value
Sheet(i).Range("F65536").End(xlUp).Offset(1) = TextBox5.Value
Sheet(i).Range("G65536").End(xlUp).Offset(1) = TextBox6.Text
Sheet(i).Range("H65536").End(xlUp).Offset(1) = ComboBox1.Text
Sheet(i).Range("I65536").End(xlUp).Offset(1) = TextBox7.Text
Sheet(i).Range("J65536").End(xlUp).Offset(1) = TextBox8.Text
Sheet(i).Range("K65536").End(xlUp).Offset(1) = TextBox9.Text
Sheet(i).Range("L65536").End(xlUp).Offset(1) = TextBox10.Text
Sheet(i).Range("M65536").End(xlUp).Offset(1) = TextBox11.Text
Sheet(i).Range("N65536").End(xlUp).Offset(1) = TextBox12.Text
Sheet(i).Range("O65536").End(xlUp).Offset(1) = TextBox16.Text
Sheet(i).Range("R65536").End(xlUp).Offset(1) = TextBox13.Text
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
TextBox10.Text = ""
TextBox11.Text = ""
TextBox12.Text = ""
TextBox16.Text = ""
ComboBox1.Text = ""
End Sub
最佳答案
2011-11-9 11:05
  1. Private Sub CommandButton1_Click()
  2. Dim i As Integer
  3. Dim j As Integer
  4. Dim sht As Worksheet
  5. If TextBox3.Value = "" Then
  6. MsgBox "厚度不能为空!!"
  7. ElseIf TextBox4.Value = "" Then
  8. MsgBox "长度不能为空!!"
  9. ElseIf TextBox5.Value = "" Then
  10. MsgBox "宽度不能为空!!"
  11. ElseIf TextBox6.Value = "" Then
  12. MsgBox "片数不能为空!!"
  13. ElseIf ComboBox1.Value = "" Then
  14. MsgBox "请选择包装方式!!"
  15. ElseIf TextBox16.Value = "" Then
  16. MsgBox "批次不能为空!!无批次请输入0!"
  17. ElseIf 班组选择.ComboBox1.Value = "第一生产线" Then
  18. one
  19. ElseIf 班组选择.ComboBox1.Value = "第二生产线" Then
  20. two
  21. ElseIf 班组选择.ComboBox1.Value = "第三生产线" And 班组选择.ComboBox4.Value = "普通白玻" Then
  22. Set sht = Sheet9
  23. ElseIf 班组选择.ComboBox1.Value = "第三生产线" And 班组选择.ComboBox4.Value = "超白玻璃" Then
  24. Set sht = Sheet7
  25. ElseIf 班组选择.ComboBox1.Value = "第四生产线" And 班组选择.ComboBox4.Value = "普通白玻" Then
  26. Set sht = Sheet8
  27. End If

  28. With sht.Range("A65536").End(xlUp)
  29.     .Offset(1) = TextBox14.Text
  30.     .Offset(1, 1) = TextBox1.Text
  31.     .Offset(1, 2) = TextBox2.Text
  32.     .Offset(1, 3) = TextBox3.Value
  33.     .Offset(1, 4) = TextBox4.Value
  34.     .Offset(1, 5) = TextBox5.Value
  35.     .Offset(1, 6) = TextBox6.Text
  36.     .Offset(1, 7) = ComboBox1.Text
  37.     .Offset(1, 8) = IIf(TextBox7.Text = "", 0, TextBox7.Value)
  38.     .Offset(1, 9) = IIf(TextBox8.Text = "", 0, TextBox8.Value)
  39.     .Offset(1, 10) = IIf(TextBox9.Text = "", 0, TextBox9.Value)
  40.     .Offset(1, 11) = IIf(TextBox10.Text = "", 0, TextBox10.Value)
  41.     .Offset(1, 12) = IIf(TextBox11.Text = "", 0, TextBox11.Value)
  42.     .Offset(1, 13) = IIf(TextBox12.Text = "", 0, TextBox12.Value)
  43.     .Offset(1, 14) = TextBox16.Text
  44.     .Offset(1, 17) = IIf(TextBox13.Text = "", "无", TextBox13.Value)
  45. End With
  46. TextBox3.Text = ""
  47. TextBox4.Text = ""
  48. TextBox5.Text = ""
  49. TextBox6.Text = ""
  50. TextBox7.Text = ""
  51. TextBox8.Text = ""
  52. TextBox9.Text = ""
  53. TextBox10.Text = ""
  54. TextBox11.Text = ""
  55. TextBox12.Text = ""
  56. TextBox16.Text = ""
  57. ComboBox1.Text = ""
  58. End Sub
复制代码
 楼主| 发表于 2011-11-9 08:05 | 显示全部楼层
本帖最后由 hytsky 于 2011-11-9 14:44 编辑
mxg825 发表于 2011-11-9 00:07
上传附件,你的代码 需要优化!


已上传附件,登陆密码123 谢谢
回复

使用道具 举报

发表于 2011-11-9 11:05 | 显示全部楼层    本楼为最佳答案   
  1. Private Sub CommandButton1_Click()
  2. Dim i As Integer
  3. Dim j As Integer
  4. Dim sht As Worksheet
  5. If TextBox3.Value = "" Then
  6. MsgBox "厚度不能为空!!"
  7. ElseIf TextBox4.Value = "" Then
  8. MsgBox "长度不能为空!!"
  9. ElseIf TextBox5.Value = "" Then
  10. MsgBox "宽度不能为空!!"
  11. ElseIf TextBox6.Value = "" Then
  12. MsgBox "片数不能为空!!"
  13. ElseIf ComboBox1.Value = "" Then
  14. MsgBox "请选择包装方式!!"
  15. ElseIf TextBox16.Value = "" Then
  16. MsgBox "批次不能为空!!无批次请输入0!"
  17. ElseIf 班组选择.ComboBox1.Value = "第一生产线" Then
  18. one
  19. ElseIf 班组选择.ComboBox1.Value = "第二生产线" Then
  20. two
  21. ElseIf 班组选择.ComboBox1.Value = "第三生产线" And 班组选择.ComboBox4.Value = "普通白玻" Then
  22. Set sht = Sheet9
  23. ElseIf 班组选择.ComboBox1.Value = "第三生产线" And 班组选择.ComboBox4.Value = "超白玻璃" Then
  24. Set sht = Sheet7
  25. ElseIf 班组选择.ComboBox1.Value = "第四生产线" And 班组选择.ComboBox4.Value = "普通白玻" Then
  26. Set sht = Sheet8
  27. End If

  28. With sht.Range("A65536").End(xlUp)
  29.     .Offset(1) = TextBox14.Text
  30.     .Offset(1, 1) = TextBox1.Text
  31.     .Offset(1, 2) = TextBox2.Text
  32.     .Offset(1, 3) = TextBox3.Value
  33.     .Offset(1, 4) = TextBox4.Value
  34.     .Offset(1, 5) = TextBox5.Value
  35.     .Offset(1, 6) = TextBox6.Text
  36.     .Offset(1, 7) = ComboBox1.Text
  37.     .Offset(1, 8) = IIf(TextBox7.Text = "", 0, TextBox7.Value)
  38.     .Offset(1, 9) = IIf(TextBox8.Text = "", 0, TextBox8.Value)
  39.     .Offset(1, 10) = IIf(TextBox9.Text = "", 0, TextBox9.Value)
  40.     .Offset(1, 11) = IIf(TextBox10.Text = "", 0, TextBox10.Value)
  41.     .Offset(1, 12) = IIf(TextBox11.Text = "", 0, TextBox11.Value)
  42.     .Offset(1, 13) = IIf(TextBox12.Text = "", 0, TextBox12.Value)
  43.     .Offset(1, 14) = TextBox16.Text
  44.     .Offset(1, 17) = IIf(TextBox13.Text = "", "无", TextBox13.Value)
  45. End With
  46. TextBox3.Text = ""
  47. TextBox4.Text = ""
  48. TextBox5.Text = ""
  49. TextBox6.Text = ""
  50. TextBox7.Text = ""
  51. TextBox8.Text = ""
  52. TextBox9.Text = ""
  53. TextBox10.Text = ""
  54. TextBox11.Text = ""
  55. TextBox12.Text = ""
  56. TextBox16.Text = ""
  57. ComboBox1.Text = ""
  58. End Sub
复制代码

评分

参与人数 1 +1 收起 理由
hytsky + 1

查看全部评分

回复

使用道具 举报

发表于 2011-11-9 14:49 | 显示全部楼层
最佳答案暂时被关闭!
送你一个代码优化!
ComboBox1.AddItem "第一生产线"
ComboBox1.AddItem "第二生产线"
ComboBox1.AddItem "第三生产线"
ComboBox1.AddItem "第四生产线"

可以改为:
ComboBox1.List = Array("第一生产线", "第二生产线", "第三生产线", "第四生产线")
回复

使用道具 举报

 楼主| 发表于 2011-11-9 14:46 | 显示全部楼层
mxg825 发表于 2011-11-9 11:05

怎么现在给不了最佳答案了啊,我只能用评分的了
回复

使用道具 举报

发表于 2011-11-9 00:07 | 显示全部楼层
上传附件,你的代码 需要优化!
回复

使用道具 举报

 楼主| 发表于 2011-11-9 15:22 | 显示全部楼层
mxg825 发表于 2011-11-9 14:49
最佳答案暂时被关闭!
送你一个代码优化!
ComboBox1.AddItem "第一生产线"

非常感谢你
回复

使用道具 举报

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

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-14 08:43 , Processed in 0.235627 second(s), 8 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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