有人能告诉我为什么函数显示类型不匹配吗If Not j Is Nothing Then
我正在尝试制作一个宏来在一张工作表(此处称为报告表)中搜索变量列表(该变量旁边的单元格具有特定值),另一张工作表具有这些变量及其新值,并将它们复制到报告表以进行比较。
如果我声明j
为,range
那么我将无法搜索,因为我必须删除.select
并添加设置j
到下面的行
j = Range("h1:q3000").find(What:=variablename).Select
Option Explicit
Sub search_and_find()
Dim datasheet As Worksheet
Dim reportsheet As Worksheet
Dim variablename As String
Dim finalrow As Integer
Dim i As Integer
Dim j As String
Dim k As Integer
Dim finalrsheet As Integer
Set datasheet = Sheet1
Set reportsheet = Sheet2
reportsheet.Select
Range("a1").Select
With ActiveSheet
finalrsheet = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
For i = 2 To finalrsheet
Cells(i, 1).Select
Selection.Copy
Sheet3.Activate
Range("a1").PasteSpecial
variablename = Range("a1")
datasheet.Activate
j = Range("h1:q3000").find(What:=variablename).Select
If Not j Is Nothing Then
Selection.Offset(0, 5).Copy
reportsheet.Activate
Cells(i, 4).PasteSpecial
Else
reportsheet.Activate
Cells(i, 5).Value = "Need to find Manually"
End If
Next i
reportsheet.Activate
For k = 2 To finalrsheet
If Cells(k, 5).Value = "Need to find Manually" Then
Cells(k, 5).Value = "Need to find Manually"
ElseIf Cells(k, 2).Value = Cells(k, 4).Value Then
Cells(k, 5).Value = "No change"
Else
Cells(k, 5).Value = "Changed"
End If
Next k
End Sub