Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.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 删除“1”之前的所有行(第1行除外);“TH值”;_Excel_Vba - Fatal编程技术网

Excel 删除“1”之前的所有行(第1行除外);“TH值”;

Excel 删除“1”之前的所有行(第1行除外);“TH值”;,excel,vba,Excel,Vba,我试图做的是删除绿色突出显示“TH值”之前的所有行 我几乎什么都试过了,但收效甚微。我确实需要帮助 Sub Search_Range_For_Text() Dim cell As Range For Each cell In Range("b1:b100") If InStr(1, cell.Value, "After Upd") > 0 Then cell.Offset(0, 0).Value = "TH Value"

我试图做的是删除绿色突出显示“TH值”之前的所有行

我几乎什么都试过了,但收效甚微。我确实需要帮助

Sub Search_Range_For_Text()
Dim cell As Range

    For Each cell In Range("b1:b100")
        If InStr(1, cell.Value, "After Upd") > 0 Then
            cell.Offset(0, 0).Value = "TH Value"
            cell.Interior.ColorIndex = 4

            MsgBox "Scroll down to find TH Value which is highlighted green.  Check field notes to verify if there was a check shot"
        Exit For
      End If

Next cell

End Sub
这张图片代表了我正在努力实现的结果:

Sub DeleteBelow()
    Dim cell As Range
    '// Set find format: green color
    With Application.FindFormat.Interior
        .Color = RGB(0, 255, 0) '//green color
    End With
    '// Set 'SearchFormat = True' to use FindFormat
    Set cell = Range("B:B").Find(What:="*", SearchFormat:=True)
    If Not cell Is Nothing Then
        If cell.Row > 2 Then
            '// Delete all rows beneath found cell (down to the last sheet row)
            Rows("2:" & cell.Row - 1).Delete
    Else
        MsgBox "No cell was found.", vbExclamation
    End If
End Sub

所以我认为它解决了这个问题

一旦我封锁了“如果不是细胞是什么”,然后它开始工作

下表() 暗淡单元格作为范围 “//设置查找格式:绿色 使用Application.FindFormat.Interior .Color=RGB(0,255,0)//绿色 以 “//设置“SearchFormat=True”以使用FindFormat 设置单元格=范围(“B:B”)。查找(内容:=“*”,搜索格式:=True) “如果非单元格为空,则”阻止此语句 如果cell.Row>2,则 “//删除找到的单元格下的所有行(一直到最后一行) 行(“2:&cell.Row-1”)。删除 其他的 “MsgBox”未找到单元格。“,请使用感叹号 如果结束


End Sub

我看你的两张照片是一样的吗?两者似乎都不符合您所述的问题。欢迎使用SO!请拿着这本书读一读!避免使用隐式ActiveSheet引用。为此工作簿中的每个单元格使用
。工作表(“Sheetname”)。范围(“b1:b100”)
嘿!请查看我的新帖子。编译错误,但在我看来是正确的。有什么建议吗?