【发布时间】:2017-03-18 16:11:56
【问题描述】:
我正在尝试使用此代码在一张纸中搜索某些内容并将其移动到另一张纸上。下面是我的代码。我不断收到此错误:
Run-time error '1004':
Application-defined or object-defined error
代码:
Private Sub CommandButton1_Click()
Dim ws As Worksheet, myCounter
Dim erow, myValue As Long
For Each ws In Sheets
If ws.Range("C3").Value > 6 Then
myCounter = 1
ws.Select
ws.Range("C3").Select
myValue = ws.Range("C3").Value
Worksheets("Report").Select
erow = ActiveSheet.Cells(Rows.Count, 1).End(x1Up).Offset(1, 0).Row
ActiveSheet.Cells(erow, 1) = myValue
nextValue = MsgBox("Value found in " & ws.Name & Chr(10) & "Continue?", vbInformation + vbYesvbNo, ws.Name & " C3 = " & ws.Range("C3").Value)
Select Case nextValue
Case Is = vbYes
Case Is = vbNo
Exit Sub
End Select
End If
Next ws
If myCounter = 0 Then
MsgBox "None of the sheets contains a " & Chr(10) & "value greater than 6 in cell C3 ", vbInformation, "Not Found"
End If
End Sub
为什么会出现这个错误?
**Run-time error '1004':
Application-defined or object-defined error**
【问题讨论】:
-
请写好标题。
-
出现该错误时突出显示哪一行?
-
您的代码中有拼写错误。
.End(x1Up)应该是.End(xlUp)