Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 长字符串和。查找_Excel_Vba - Fatal编程技术网

Excel 长字符串和。查找

Excel 长字符串和。查找,excel,vba,Excel,Vba,我尝试在以下代码中使用.Find方法,但在这一行中出现了“类型不匹配”错误: Set Rng = SuchBereich.Find(What:=zelle.Value, LookAt:=xlWhole)` 程序如下: Sub test() 'Define Fields Dim anzzeilen As Long Dim SuchBereich As Range Dim Bereich As Range Dim t1 As Long Dim t2 As Long 'Define SuchBe

我尝试在以下代码中使用
.Find
方法,但在这一行中出现了“类型不匹配”错误:

Set Rng = SuchBereich.Find(What:=zelle.Value, LookAt:=xlWhole)`
程序如下:

Sub test()

'Define Fields
Dim anzzeilen As Long
Dim SuchBereich As Range
Dim Bereich As Range
Dim t1 As Long
Dim t2 As Long

'Define SuchBereich as range
With ThisWorkbook.Worksheets(1)
anzzeilen = .Cells(Rows.Count, 1).End(xlUp).Row
Set SuchBereich = .Range(.Cells(1, 5), .Cells(anzzeilen, 6))
End With

'Define Bereich as Range
With ThisWorkbook.Worksheets(1)
t1 = .Cells(Rows.Count, 1).End(xlUp).Row
Set Bereich = .Range(.Cells(1, 1), .Cells(t1, 1))
End With

For Each zelle In Bereich
        If zelle.Value <> "" Then
            Set Rng = SuchBereich.Find(What:=zelle.Value, LookAt:=xlWhole) '<--ERROR
            'Debug.Print Rng.Address
            If Not Rng Is Nothing Then
            Debug.Print zelle.Address
                zelle.Interior.ColorIndex = 12
            End If
        End If
Next zelle
End Sub
子测试()
'定义字段
Dim anzzeilen和Long一样长
像射程一样暗淡
Dim Bereich As系列
暗t1与长t1相同
变暗t2与长t2相同
“将此类区域定义为范围
使用此工作簿。工作表(1)
anzzeilen=.Cells(Rows.Count,1).End(xlUp).Row
设置SuchBereich=.Range(.Cells(1,5),.Cells(anzzeilen,6))
以
“将Bereich定义为范围
使用此工作簿。工作表(1)
t1=.Cells(Rows.Count,1).End(xlUp).Row
设置Bereich=.Range(.Cells(1,1),.Cells(t1,1))
以
为了贝里希的每一个泽尔
如果zelle.Value为“”,则

设置Rng=SuchBereich.Find(What:=zelle.Value,LookAt:=xlWhole)您的示例字符串长度为401个字符。看起来
Find
最多只能处理256个字符


另一种方法是只搜索可以唯一标识每个字符串的子字符串。例如,可以是前256个字符,或最后256个字符,或中间256个字符,或任何足够长的字符;可能不需要256个字符

你在哪一行得到这个错误?我不打算阅读你的全部代码来解决这个问题……我得到的错误是:Set Rng=SuchBereich.Find(What:=zelle.Value,LookAt:=xlother)好的,我们在你的问题中写下,而不是评论。这次是为你做的。你的示例字符串是401个字符长!看起来
Find
最多只能处理256个字符。你真的需要搜索这么长的字符串吗??你想达到什么目的?我(平均)对工作簿1有100条评论。我取了50个样本,将它们复制到工作簿2的a页上。然后我复制工作簿2工作表B上的所有注释并关闭工作簿1。现在,我想识别表B上的所有示例注释(表A),并通过给它们另一种背景颜色来突出显示它们。