用excel中VBA编辑录入模块,运行时发现“方法和数据成员未找到”
PrivateSubCommandButton1_Click()DimlineAsIntegerline=0Worksheets("sheet1").SelectRang...
Private Sub CommandButton1_Click()
Dim line As Integer
line = 0
Worksheets("sheet1").Select
Range("a2").Select
For i = 1 To 65534 Step 1
If ActiveCell.Value = Empty Then
Exit For
Else
Range("a2").Offset(i, o).Select
line = line + 1
End If
Next i
Range("a2").Offset(line, 0).Value = UserForm1.text1.Text
Range("a2").Offset(line, 1).Value = UserForm1.text2.Text
Range("a2").Offset(line, 2).Value = UserForm1.combox1.Text
Range("a2").Offset(line, 3).Value = UserForm1.text3.Text
Range("a2").Offset(line, 4).Value = UserForm1.text4.Text
Range("a2").Offset(line, 5).Value = UserForm1.text5.Text
Range("a2").Offset(line, 6).Value = UserForm1.text6.Text
Range("a2").Offset(line, 7).Value = UserForm1.combox2.Text
Range("a2").Offset(line, 8).Value = UserForm1.text7.Text
Range("a2").Offset(line, 9).Value = UserForm1.combox3.Text
Range("a2").Offset(line, 10).Value = UserForm1.text8.Text
End Sub 展开
Dim line As Integer
line = 0
Worksheets("sheet1").Select
Range("a2").Select
For i = 1 To 65534 Step 1
If ActiveCell.Value = Empty Then
Exit For
Else
Range("a2").Offset(i, o).Select
line = line + 1
End If
Next i
Range("a2").Offset(line, 0).Value = UserForm1.text1.Text
Range("a2").Offset(line, 1).Value = UserForm1.text2.Text
Range("a2").Offset(line, 2).Value = UserForm1.combox1.Text
Range("a2").Offset(line, 3).Value = UserForm1.text3.Text
Range("a2").Offset(line, 4).Value = UserForm1.text4.Text
Range("a2").Offset(line, 5).Value = UserForm1.text5.Text
Range("a2").Offset(line, 6).Value = UserForm1.text6.Text
Range("a2").Offset(line, 7).Value = UserForm1.combox2.Text
Range("a2").Offset(line, 8).Value = UserForm1.text7.Text
Range("a2").Offset(line, 9).Value = UserForm1.combox3.Text
Range("a2").Offset(line, 10).Value = UserForm1.text8.Text
End Sub 展开
展开全部
Range("a2").Offset(i, o).Select 这句错了,数字0 写成了 字母o
另外,vba中控件的默认名字与vb中不同,注意区别:
.Text1 ,文本框 默认的名字为 .TextBox1
.combox1 ,复合框 默认名字为 .ComboBox1
给你优化了代码:
---------------
Private Sub CommandButton1_Click()
Dim a, i
With Worksheets("sheet1").Range("a2")
For i = 1 To 65534
If .Cells(i, o) = "" Then
With UserForm1
a = Array(.TextBox1.Text, .TextBox2.Text, .ComboBox1.Text, _
.TextBox3.Text, .TextBox4.Text, .TextBox5.Text, _
.TextBox6.Text, .ComboBox2.Text, .TextBox7.Text, _
.ComboBox3.Text, .TextBox8.Text)
End With
.Cells(i, 1).Resize(1, 11) = a
Exit For
End If
Next i
End With
End Sub
另外,vba中控件的默认名字与vb中不同,注意区别:
.Text1 ,文本框 默认的名字为 .TextBox1
.combox1 ,复合框 默认名字为 .ComboBox1
给你优化了代码:
---------------
Private Sub CommandButton1_Click()
Dim a, i
With Worksheets("sheet1").Range("a2")
For i = 1 To 65534
If .Cells(i, o) = "" Then
With UserForm1
a = Array(.TextBox1.Text, .TextBox2.Text, .ComboBox1.Text, _
.TextBox3.Text, .TextBox4.Text, .TextBox5.Text, _
.TextBox6.Text, .ComboBox2.Text, .TextBox7.Text, _
.ComboBox3.Text, .TextBox8.Text)
End With
.Cells(i, 1).Resize(1, 11) = a
Exit For
End If
Next i
End With
End Sub
追问
刚才试过了,还是出现这个问题。麻烦大侠给修改下,我是EXCEL2007
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |