【发布时间】:2016-10-19 14:58:59
【问题描述】:
我正在开发一个宏,它应该将数据传输到名为“pistoia”的不同工作表中,这是代码:
Sub SetCounter(ByVal counter As Double, ByVal product As String)
Dim ws As Worksheet
On Error Resume Next
Sheets("pistoia").Activate
Set ws = ActiveWorkbook.Sheets("pistoia")
On Error GoTo 0
If ws Is Nothing Then
MsgBox "pistoia sheet not found"
Else
If ws.Name = ActiveWorkbook.ActiveSheet.Name Then
Dim index_destRow As Integer, index_destColumn As Integer, search_product As Range
Rows(2).Find(What:="Nome commerciale", LookAt:=xlWhole, LookIn:=xlValues).Offset(2).Select
Else
MsgBox "pistoia sheet found but is inactive"
End If
End If
End Sub
错误出现在以下行:“Rows(2).Find(What:="Nome Commerciale", LookAt:=xlWhole, LookIn:=xlValues).Offset(2).Select”,我认为错误是由于激活了新工作表,因为在之前的“在起始工作表上”制作的宏中,我在导致错误的行中运行了相同的操作。有什么建议吗?
【问题讨论】:
-
在
Rows(2)前面添加ws.。将亲子关系分配给对象可确保调用作用于所需的指定对象。另一件事是确保“商业名称”存在于您要查找的位置。 -
我用 ws 试过了。但没有任何改变......是的,我检查了第 2 行
-
如果您在命令前添加
debug.print并将.Select更改为.Value。错误是否仍然存在?还是在即时窗口中返回一个值? -
错误仍然存在,即时窗口上没有写入任何内容