vba代码编写求助!我做了一个窗体,想实现点击查询后能显示已经输入了的信息,同时按修改的时候能对已
vba代码编写求助!我做了一个窗体,想实现点击查询后能显示已经输入了的信息,同时按修改的时候能对已输入的信息进行修改!!拜托了...
vba代码编写求助!我做了一个窗体,想实现点击查询后能显示已经输入了的信息,同时按修改的时候能对已输入的信息进行修改!!拜托了
展开
1个回答
展开全部
这个难度不大,我来试试吧,加我呢称。发附件来。
窗体代码如下:
Sub aaa()
Dim mrow As Long
mrow = Range("a65536").End(xlUp).Row + 1
Range("a" & mrow) = TextBox1.Value
Range("c" & mrow) = TextBox2.Value
Range("b" & mrow) = ComboBox1.Value
Range("d" & mrow) = ComboBox2.Value
Range("e" & mrow) = ComboBox3.Value
'Range("f" & mrow) = TextBox3.Value & "分" & TextBox4.Value & "秒"
Range("f" & mrow) = TextBox4.Value
If OptionButton1.Value = True Then
Range("g" & mrow) = OptionButton1.Caption
ElseIf OptionButton2.Value = True Then
Range("g" & mrow) = OptionButton2.Caption
ElseIf OptionButton3.Value = True Then
Range("g" & mrow) = OptionButton3.Caption
End If
End Sub
Private Sub UserForm_Initialize()
ComboBox1.AddItem "男"
ComboBox1.AddItem "女"
ComboBox2.AddItem "博士"
ComboBox2.AddItem "硕士"
ComboBox2.AddItem "大学"
ComboBox2.AddItem "高中"
ComboBox2.AddItem "初中"
ComboBox3.AddItem "第一组"
ComboBox3.AddItem "第二组"
ComboBox3.AddItem "第三组"
ComboBox3.AddItem "第四组"
End Sub
Private Sub 查询_Click()
Dim mcol As Integer
Dim mrow1 As Long
mrow1 = Range("A:A").Find(TextBox1.Value).Row
TextBox2.Value = Range("c" & mrow1)
TextBox4.Value = Range("f" & mrow1)
ComboBox1.Value = Range("B" & mrow1)
ComboBox2.Value = Range("D" & mrow1)
ComboBox3.Value = Range("E" & mrow1)
If Range("G" & mrow1).Value = OptionButton1.Caption Then
OptionButton1.Value = 1
ElseIf Range("G" & mrow1).Value = OptionButton2.Caption Then
OptionButton2.Value = 1
ElseIf Range("G" & mrow1).Value = OptionButton3.Caption Then
OptionButton3.Value = 1
End If
End Sub
Private Sub 清空数据_Click()
TextBox1.Value = ""
TextBox2.Value = ""
ComboBox1.Value = ""
ComboBox2.Value = ""
ComboBox3.Value = ""
TextBox4.Value = ""
OptionButton1.Value = 0
OptionButton2.Value = 0
OptionButton3.Value = 0
End Sub
Private Sub 添加_Click()
Call aaa
MsgBox "添加成功", 64
End Sub
Private Sub 退出_Click()
Unload UserForm1
End Sub
Private Sub 修改_Click()
Dim mcol As Integer
Dim mrow1 As Long
mrow1 = Range("A:A").Find(TextBox1.Value).Row
Rows(mrow1).Delete
Call aaa
MsgBox "修改成功", 64
窗体代码如下:
Sub aaa()
Dim mrow As Long
mrow = Range("a65536").End(xlUp).Row + 1
Range("a" & mrow) = TextBox1.Value
Range("c" & mrow) = TextBox2.Value
Range("b" & mrow) = ComboBox1.Value
Range("d" & mrow) = ComboBox2.Value
Range("e" & mrow) = ComboBox3.Value
'Range("f" & mrow) = TextBox3.Value & "分" & TextBox4.Value & "秒"
Range("f" & mrow) = TextBox4.Value
If OptionButton1.Value = True Then
Range("g" & mrow) = OptionButton1.Caption
ElseIf OptionButton2.Value = True Then
Range("g" & mrow) = OptionButton2.Caption
ElseIf OptionButton3.Value = True Then
Range("g" & mrow) = OptionButton3.Caption
End If
End Sub
Private Sub UserForm_Initialize()
ComboBox1.AddItem "男"
ComboBox1.AddItem "女"
ComboBox2.AddItem "博士"
ComboBox2.AddItem "硕士"
ComboBox2.AddItem "大学"
ComboBox2.AddItem "高中"
ComboBox2.AddItem "初中"
ComboBox3.AddItem "第一组"
ComboBox3.AddItem "第二组"
ComboBox3.AddItem "第三组"
ComboBox3.AddItem "第四组"
End Sub
Private Sub 查询_Click()
Dim mcol As Integer
Dim mrow1 As Long
mrow1 = Range("A:A").Find(TextBox1.Value).Row
TextBox2.Value = Range("c" & mrow1)
TextBox4.Value = Range("f" & mrow1)
ComboBox1.Value = Range("B" & mrow1)
ComboBox2.Value = Range("D" & mrow1)
ComboBox3.Value = Range("E" & mrow1)
If Range("G" & mrow1).Value = OptionButton1.Caption Then
OptionButton1.Value = 1
ElseIf Range("G" & mrow1).Value = OptionButton2.Caption Then
OptionButton2.Value = 1
ElseIf Range("G" & mrow1).Value = OptionButton3.Caption Then
OptionButton3.Value = 1
End If
End Sub
Private Sub 清空数据_Click()
TextBox1.Value = ""
TextBox2.Value = ""
ComboBox1.Value = ""
ComboBox2.Value = ""
ComboBox3.Value = ""
TextBox4.Value = ""
OptionButton1.Value = 0
OptionButton2.Value = 0
OptionButton3.Value = 0
End Sub
Private Sub 添加_Click()
Call aaa
MsgBox "添加成功", 64
End Sub
Private Sub 退出_Click()
Unload UserForm1
End Sub
Private Sub 修改_Click()
Dim mcol As Integer
Dim mrow1 As Long
mrow1 = Range("A:A").Find(TextBox1.Value).Row
Rows(mrow1).Delete
Call aaa
MsgBox "修改成功", 64
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询