收到Complie错误方法或数据成员未找到 - 使用VBA
我对VBA和本网站都是新手,如果我没有提供所有重要信息,那么我就是裸机。我正在创建一个共享工作表 - 在O列中,当他们点击时我创建了一个用户表单,提出3个问题。我需要将这些答案放入隐藏的工作表中。我写了代码,但是当我运行它时,我得到了编译错误的方法。由于我对VBA非常陌生,我确信我错过了一些我不明白的东西。有遗漏我错过的各种错误。这是我第一次,我不是刚刚复制和粘贴。所以任何帮助将不胜感激!在这种情况下,我搜索了一下,发现了一个与我正在寻找的内容相关的表单,并试图调整它以适应我需要的内容。可能是我的第一个错误!收到Complie错误方法或数据成员未找到 - 使用VBA
它突出
iRow = ws.Cells.Find(What:="*", SearchOrder:=x1Rows, _
SearchDirection:=x1Previous, LookIn:=x1Values).Row + 1
这里是我的全部代码。请请帮忙!
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("WebLeadInfo")
'find first empty row database
iRow = ws.Cells.Find(What:="*", SearchOrder:=x1Rows, _
SearchDirection:=x1Previous, LookIn:=x1Values).Row + 1
'check for a contact
If Trim(Me.txtContact.Value) = " " Then
Me.txtContact.SetFocus
MsgBox "Please enter info"
Exit Sub
End If
'copy the data to the database
'use protect and unprotect lines,
' with your password
' if worksheet is protected
With ws
' .Unportect Password:="sunway12"
.Cells(lRow, 1).Value = Me.txtContact.Value
.Cells(lRow, 3).Value = Me.txtFind.Value
.Cells(lRow, 4).Value = Me.txtSearch.Value
.Protect Password:="sunway12"
End With
'clear the data
Me.txtContact.Value = " "
Me.txtFind.Value = " "
Me.txtSearch.Value = " "
Me.txtContact.SetFocus
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
在documantation的查找方法你可以看到, 参数SearchOrder可以是下列XlSearchOrder常量之一:
xlByRows
xlByColumns
And SearchDirection可以是以下之一XlSearchDirection常量:
xlNext
xlPrevious
最后看着参数应设置为:
xlValues
所以你的情况这将是:
'find first empty row database
Dim findResult As Range
Set findResult = ws.Cells.Find(What:="*", SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues)
iRow = 1 ' in case that the sheet contains no data the first empty row is the first one
If (Not findResult Is Nothing) Then iRow = findResult.Row + 1
' ...
With ws
' .Unportect Password:="sunway12"
.Cells(iRow, 1).Value = Me.txtContact.Value
.Cells(iRow, 3).Value = Me.txtFind.Value
.Cells(iRow, 4).Value = Me.txtSearch.Value
.Protect Password:="sunway12"
End With
x1Rows(和其他人)。 他们在那里使用“一个”字符。但是,他们应该以 “L” XLROWS,拼写不X1ROWS
啊...我以为我改变了这些!谢谢!现在看看我接下来会发生什么样的错误:o) – user2216130 2013-03-27 15:10:21
有没有一个地方有人可以帮助我走过这个?我认为我高于我的头!我收到了一个新错误。运行时错误1004,应用程序定义的错误或对象定义的错误。我想我得到这些,因为我试图改变一个代码,以适应我的目的:(booo! – user2216130 2013-03-27 15:18:05
你在哪一行得到1004错误? – 2013-03-27 16:26:01
谢谢,我确定它现在看起来完全一样,它接受了它,并转移到新的错误...我不能等到我学习VBA更好! – user2216130 2013-03-27 15:26:08
你真了不起!我多么想念那些我永远不会知道的小事!谢谢soooo多!!!!! – user2216130 2013-03-27 19:06:16
不客气! – dee 2013-03-27 19:12:17