我有一段代码,在excel添加按钮的控件代码,不能按依次按顺序添加,不知道错在那,能不能帮忙修改一下,谢
PrivateSubCommandButton2_Click()DimaAsLongIfTextBox1.value=""ThenMsgBox"员工编号请勿空白",vbO...
Private Sub CommandButton2_Click()
Dim a As Long
If TextBox1.value = "" Then
MsgBox "员工编号请勿空白", vbOKOnly
Exit Sub
End If
If TextBox2.value = "" Then
MsgBox "员工姓名空白", vbOKOnly
Exit Sub
End If
If TextBox3.value = "" Then
MsgBox "性别请勿空白", vbOKOnly
Exit Sub
End If
If TextBox4.value = "" Then
MsgBox "年龄请勿空白", vbOKOnly
Exit Sub
End If
If TextBox5.value = "" Then
MsgBox "所属部门请勿空白", vbOKOnly
Exit Sub
End If
If TextBox6.value = "" Then
MsgBox "加入公司时间请勿空白", vbOKOnly
Exit Sub
End If
If TextBox7.value = "" Then
MsgBox "学历请勿空白", vbOKOnly
Exit Sub
End If
If TextBox8.value = "" Then
MsgBox "手机号码请勿空白", vbOKOnly
Exit Sub
End If
If TextBox9.value = "" Then
MsgBox "员工身份证号码请勿空白", vbOKOnly
Exit Sub
End If
Sheets("员工基本档案信息").Select
a = Val(Cells(2, 9).value)
Cells(a + 9, 1).value = TextBox1.value
Cells(a + 9, 2).value = TextBox2.value
Cells(a + 9, 3).value = TextBox3.value
Cells(a + 9, 4).value = TextBox4.value
Cells(a + 9, 5).value = TextBox5.value
Cells(a + 9, 6).value = TextBox6.value
Cells(a + 9, 7).value = TextBox7.value
Cells(a + 9, 8).value = TextBox8.value
Cells(a + 9, 9).value = TextBox9.value
End Sub
本人邮箱li111416@126.com 如果可以我可以给你加分的 展开
Dim a As Long
If TextBox1.value = "" Then
MsgBox "员工编号请勿空白", vbOKOnly
Exit Sub
End If
If TextBox2.value = "" Then
MsgBox "员工姓名空白", vbOKOnly
Exit Sub
End If
If TextBox3.value = "" Then
MsgBox "性别请勿空白", vbOKOnly
Exit Sub
End If
If TextBox4.value = "" Then
MsgBox "年龄请勿空白", vbOKOnly
Exit Sub
End If
If TextBox5.value = "" Then
MsgBox "所属部门请勿空白", vbOKOnly
Exit Sub
End If
If TextBox6.value = "" Then
MsgBox "加入公司时间请勿空白", vbOKOnly
Exit Sub
End If
If TextBox7.value = "" Then
MsgBox "学历请勿空白", vbOKOnly
Exit Sub
End If
If TextBox8.value = "" Then
MsgBox "手机号码请勿空白", vbOKOnly
Exit Sub
End If
If TextBox9.value = "" Then
MsgBox "员工身份证号码请勿空白", vbOKOnly
Exit Sub
End If
Sheets("员工基本档案信息").Select
a = Val(Cells(2, 9).value)
Cells(a + 9, 1).value = TextBox1.value
Cells(a + 9, 2).value = TextBox2.value
Cells(a + 9, 3).value = TextBox3.value
Cells(a + 9, 4).value = TextBox4.value
Cells(a + 9, 5).value = TextBox5.value
Cells(a + 9, 6).value = TextBox6.value
Cells(a + 9, 7).value = TextBox7.value
Cells(a + 9, 8).value = TextBox8.value
Cells(a + 9, 9).value = TextBox9.value
End Sub
本人邮箱li111416@126.com 如果可以我可以给你加分的 展开
展开全部
你说的不能按依次顺序是什么意思?是第9行中单元格顺序不对?还是。从第9行开始,不按行添加?如果是不按行添加。那是因为你的 a = Val(Cells(2, 9).value) 不是按顺序添加的。end sub 之前加入 a=a+1 cells(2,9).value=a就可以了。
Private Sub CommandButton2_Click()
Dim a As Long
If TextBox1.value = "" Then
MsgBox "员工编号请勿空白", vbOKOnly
Exit Sub
End If
If TextBox2.value = "" Then
MsgBox "员工姓名空白", vbOKOnly
Exit Sub
End If
If TextBox3.value = "" Then
MsgBox "性别请勿空白", vbOKOnly
Exit Sub
End If
If TextBox4.value = "" Then
MsgBox "年龄请勿空白", vbOKOnly
Exit Sub
End If
If TextBox5.value = "" Then
MsgBox "所属部门请勿空白", vbOKOnly
Exit Sub
End If
If TextBox6.value = "" Then
MsgBox "加入公司时间请勿空白", vbOKOnly
Exit Sub
End If
If TextBox7.value = "" Then
MsgBox "学历请勿空白", vbOKOnly
Exit Sub
End If
If TextBox8.value = "" Then
MsgBox "手机号码请勿空白", vbOKOnly
Exit Sub
End If
If TextBox9.value = "" Then
MsgBox "员工身份证号码请勿空白", vbOKOnly
Exit Sub
End If
Sheets("员工基本档案信息").Select
a = Val(Cells(2, 9).value)
Cells(a + 9, 1).value = TextBox1.value
Cells(a + 9, 2).value = TextBox2.value
Cells(a + 9, 3).value = TextBox3.value
Cells(a + 9, 4).value = TextBox4.value
Cells(a + 9, 5).value = TextBox5.value
Cells(a + 9, 6).value = TextBox6.value
Cells(a + 9, 7).value = TextBox7.value
Cells(a + 9, 8).value = TextBox8.value
a=a+1
cells(2,9).value=a
End Sub
Private Sub CommandButton2_Click()
Dim a As Long
If TextBox1.value = "" Then
MsgBox "员工编号请勿空白", vbOKOnly
Exit Sub
End If
If TextBox2.value = "" Then
MsgBox "员工姓名空白", vbOKOnly
Exit Sub
End If
If TextBox3.value = "" Then
MsgBox "性别请勿空白", vbOKOnly
Exit Sub
End If
If TextBox4.value = "" Then
MsgBox "年龄请勿空白", vbOKOnly
Exit Sub
End If
If TextBox5.value = "" Then
MsgBox "所属部门请勿空白", vbOKOnly
Exit Sub
End If
If TextBox6.value = "" Then
MsgBox "加入公司时间请勿空白", vbOKOnly
Exit Sub
End If
If TextBox7.value = "" Then
MsgBox "学历请勿空白", vbOKOnly
Exit Sub
End If
If TextBox8.value = "" Then
MsgBox "手机号码请勿空白", vbOKOnly
Exit Sub
End If
If TextBox9.value = "" Then
MsgBox "员工身份证号码请勿空白", vbOKOnly
Exit Sub
End If
Sheets("员工基本档案信息").Select
a = Val(Cells(2, 9).value)
Cells(a + 9, 1).value = TextBox1.value
Cells(a + 9, 2).value = TextBox2.value
Cells(a + 9, 3).value = TextBox3.value
Cells(a + 9, 4).value = TextBox4.value
Cells(a + 9, 5).value = TextBox5.value
Cells(a + 9, 6).value = TextBox6.value
Cells(a + 9, 7).value = TextBox7.value
Cells(a + 9, 8).value = TextBox8.value
a=a+1
cells(2,9).value=a
End Sub
展开全部
你的代码没有问题,仔细确认下按钮名称确实是CommandButton2吗?可能你修改了按钮名称,但是忘记修改代码了。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
增加,按钮事件,然后调用宏!
Private Sub CommandButton1_Click()
Macro1
End Sub
Private Sub CommandButton1_Click()
Macro1
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询