功能:我正在做一个小项目,我需要在列中的每个单元格中搜索单词“ Unknown”(如果包含该单词),然后将整行复制到新的工作表上。

问题:我得到“对象不支持此属性方法”。错误。我相信它在复制语句中的某个位置(不是目标)。它是如此简单,但是我似乎无法解决这个问题。

Sub CheckRows()
Dim b As Range
Dim SrchRng As Range

Set b = ActiveWorkbook.Sheets("Sheet 2").Range("A1")
Set SrchRng = ActiveWorkbook.Sheets("Sheet 1").Range("G1")

Do While SrchRng.Value <> ""
    If SrchRng.Value = "Unknown" Then
        Worksheets("Sheet 1").SrchRng.EntireRow.Copy _
            Destination:=Worksheets("Sheet 2").b
        Set b = b.Offset(1, 0)
        Set SrchRng = SrchRng.Offset(1, 0)
    Else: Set SrchRng = SrchRng.Offset(1, 0)
    End If
Loop

End Sub

最佳答案

尝试Range.EntireRow.Value属性

b.EntireRow.Value = SrchRng.EntireRow.Value




Do While SrchRng.Value <> ""
    If SrchRng.Value = "Unknown" Then
      b.EntireRow.Value = SrchRng.EntireRow.Value
    Set b = b.Offset(1, 0)
    Set SrchRng = SrchRng.Offset(1, 0)
    Else: Set SrchRng = SrchRng.Offset(1, 0)
    End If
Loop

10-07 17:14