简体   繁体   English

VBA搜索变量范围的文本

[英]VBA Search Variable Range for text

I want to write a vba macro that searches in a variable range for the value "x" and "X" and if it finds one of These values I want to hide that row. 我想编写一个在可变范围内搜索值“ x”和“ X”的vba宏,如果它找到这些值之一,我想隐藏该行。 I know how to make a range variable with range(Cells(row, column),cells(row, column)) but when I Combine the variable range with the search I can't get it runnning. 我知道如何使用range(Cells(row,column),cells(row,column))来使范围变量可变,但是当我将变量范围与搜索结合起来时,我无法运行它。

Sub zeilen_ausblenden()
    Dim count As Integer
    Dim maxrow As Integer

    maxrow = Worksheets("Anwendungen -> Prozesse ").UsedRange.Rows.count


    For Row = 11 To maxrow

        count = WorksheetFunction.Range("K" & Row & ":KB" & Row).Find("x", "X", LookIn:=xlValues)

        If count > 0 Then
        Else

            Rows(Row).EntireRow.Hidden = True

        End If

    Next

End Sub

Try this code: 试试这个代码:

Sub zeilen_ausblenden()
    Dim wks As Excel.Worksheet
    Dim found As Excel.Range
    Dim maxRow As Integer
    Dim row As Long
    '-----------------------------------------------------------


    Set wks = Worksheets("Anwendungen -> Prozesse ")
    With wks.UsedRange
        maxRow = .row + .Rows.count - 1
    End With


    For row = 11 To maxRow

        Set found = wks.Range("K" & row & ":KB" & row).Find("x", LookIn:=xlValues, MatchCase:=False)

        If Not found Is Nothing Then
            wks.Rows(row).EntireRow.Hidden = True
        End If

    Next

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM