VBA搜索文本的可變范圍 - VBA Search Variable Range for text -开发者知识库

VBA搜索文本的可變范圍 - VBA Search Variable Range for text -开发者知识库,第1张

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. 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.

我想編寫一個vba宏,在變量范圍內搜索值“x”和“X”,如果找到其中一個值,我想隱藏該行。我知道如何使用范圍(單元格(行,列),單元格(行,列))創建范圍變量,但是當我將變量范圍與搜索組合時,我無法使其運行。

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

1 个解决方案

#1


0  

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

最佳答案:

本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复