VBA Excel错误13类型不匹配
我的下一个代码是在两个工作表中验证ID,它可以正常工作,但每次我运行宏时,我都会出现不匹配错误,我不知道我做错了什么,或者我不知道我是否遗漏了什么,在来到这里之前,我已经检查了所有答案,但仍然没有任何结果 错误发生在VBA Excel错误13类型不匹配,vba,excel,Vba,Excel,我的下一个代码是在两个工作表中验证ID,它可以正常工作,但每次我运行宏时,我都会出现不匹配错误,我不知道我做错了什么,或者我不知道我是否遗漏了什么,在来到这里之前,我已经检查了所有答案,但仍然没有任何结果 错误发生在Set j=.Range(“A:A”).find(findValue) 这是我的代码: Sub Save_comments() Dim i As Integer Dim j As Range k = Sheets("List").Cells(Rows.Count, "P").End
Set j=.Range(“A:A”).find(findValue)
这是我的代码:
Sub Save_comments()
Dim i As Integer
Dim j As Range
k = Sheets("List").Cells(Rows.Count, "P").End(xlUp).Row
For i = 1 To k
findValue = Sheets("List").Cells(i, 16).Value
With Sheets("Historical_Data")
l = .Cells(Rows.Count, "A").End(xlUp).Row + 1
Set j = .Range("A:A").find(findValue) '<-- error here
If Not j Is Nothing Then
If Sheets("List").Cells(i, 18).Value <> "" Then
.Cells(j.Row, j.Column).Offset(0, 2).Value = Sheets("List").Cells(i, 18).Value
End If
Else
.Cells(l, 1).Value = Sheets("List").Cells(i, 16).Value
.Cells(l, 3).Value = Sheets("List").Cells(i, 18).Value
End If
End With
Next i
End Sub
Sub Save_comments()
作为整数的Dim i
尺寸j As范围
k=工作表(“列表”)。单元格(行数,“P”)。结束(xlUp)。行
对于i=1到k
findValue=表格(“列表”).单元格(i,16).值
带图纸(“历史数据”)
l=.Cells(Rows.Count,“A”).End(xlUp).Row+1
Set j=.Range(“A:A”).find(findValue)”这就是代码的最小版本的外观:
Sub SaveComments()
Dim i As Long
Dim j As Range
Dim findValue As String
For i = 1 To 20
findValue = Sheets("List").Cells(i, 16).Value
With Sheets("Historical_Data")
Set j = .Range("A:A").Find(findValue) '<-- error here
Debug.Print j.Address
End With
Next i
End Sub
Sub SaveComments()
我想我会坚持多久
尺寸j As范围
作为字符串的Dim findValue
对于i=1到20
findValue=表格(“列表”).单元格(i,16).值
带图纸(“历史数据”)
Set j=.Range(“A:A”).Find(findValue)”这就是代码的最小版本的外观:
Sub SaveComments()
Dim i As Long
Dim j As Range
Dim findValue As String
For i = 1 To 20
findValue = Sheets("List").Cells(i, 16).Value
With Sheets("Historical_Data")
Set j = .Range("A:A").Find(findValue) '<-- error here
Debug.Print j.Address
End With
Next i
End Sub
Sub SaveComments()
我想我会坚持多久
尺寸j As范围
作为字符串的Dim findValue
对于i=1到20
findValue=表格(“列表”).单元格(i,16).值
带图纸(“历史数据”)
设置j=.Range(“A:A”).Find(findValue)尝试按如下方式修改代码:
Sub Save_comments()
Dim i As Integer
Dim j As Range
k = Sheets("List").Cells(Rows.Count, "P").End(xlUp).Row
For i = 1 To k
findValue = Sheets("List").Cells(i, 16).Value
If Application.IsNA(findValue) = False Then
With Sheets("Historical_Data")
l = .Cells(Rows.Count, "A").End(xlUp).Row + 1
Set j = .Range("A:A").Find(findValue) '<-- error here
If Not j Is Nothing Then
If Sheets("List").Cells(i, 18).Value <> "" Then
.Cells(j.Row, j.Column).Offset(0, 2).Value = Sheets("List").Cells(i, 18).Value
End If
Else
.Cells(l, 1).Value = Sheets("List").Cells(i, 16).Value
.Cells(l, 3).Value = Sheets("List").Cells(i, 18).Value
End If
End With
End If
Next i
End Sub
Sub Save_comments()
作为整数的Dim i
尺寸j As范围
k=工作表(“列表”)。单元格(行数,“P”)。结束(xlUp)。行
对于i=1到k
findValue=表格(“列表”).单元格(i,16).值
如果Application.IsNA(findValue)=False,则
带图纸(“历史数据”)
l=.Cells(Rows.Count,“A”).End(xlUp).Row+1
设置j=.Range(“A:A”).Find(findValue)尝试按如下方式修改代码:
Sub Save_comments()
Dim i As Integer
Dim j As Range
k = Sheets("List").Cells(Rows.Count, "P").End(xlUp).Row
For i = 1 To k
findValue = Sheets("List").Cells(i, 16).Value
If Application.IsNA(findValue) = False Then
With Sheets("Historical_Data")
l = .Cells(Rows.Count, "A").End(xlUp).Row + 1
Set j = .Range("A:A").Find(findValue) '<-- error here
If Not j Is Nothing Then
If Sheets("List").Cells(i, 18).Value <> "" Then
.Cells(j.Row, j.Column).Offset(0, 2).Value = Sheets("List").Cells(i, 18).Value
End If
Else
.Cells(l, 1).Value = Sheets("List").Cells(i, 16).Value
.Cells(l, 3).Value = Sheets("List").Cells(i, 18).Value
End If
End With
End If
Next i
End Sub
Sub Save_comments()
作为整数的Dim i
尺寸j As范围
k=工作表(“列表”)。单元格(行数,“P”)。结束(xlUp)。行
对于i=1到k
findValue=表格(“列表”).单元格(i,16).值
如果Application.IsNA(findValue)=False,则
带图纸(“历史数据”)
l=.Cells(Rows.Count,“A”).End(xlUp).Row+1
Set j=.Range(“A:A”).Find(findValue)”您是否将j
声明为任何内容?如果没有,则添加尺寸j作为范围
。无论如何都要使用Option Explicit并声明所有变量。Hi@SJR,我做了,但仍然是相同的错误。当它出错时,findValue
的值是多少?请做一个说明,否则很难帮助您。我认为如果单元格包含错误值,则会发生错误,因此请先使用iError或类似工具添加检查。您是否声明了j
?如果没有,则添加尺寸j作为范围
。无论如何都要使用Option Explicit并声明所有变量。您好@SJR,我做了,但仍然是相同的错误。当它出错时,findValue
的值是多少?请做一个提示,否则很难帮助您。我认为如果单元格包含错误值,则会发生错误,因此请首先使用iError或类似工具添加一个检查。非常感谢您的回答!我真的很感激。我找到了解决办法。祝您有个美好的一天!非常感谢你的回答!我真的很感激。我找到了解决办法。祝您有个美好的一天!