2015-07-28 28 views
0

我想編寫一個vba宏,它在變量範圍內搜索值「x」和「X」,並且如果找到其中一個這些值,我想隱藏該行。 我知道如何使用範圍(單元格(行,列),單元格(行,列))來創建範圍變量,但是當我將變量範圍與搜索結合起來時,我無法使其運行。用於文本的VBA搜索變量範圍

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 

回答

0

試試這個代碼:

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

非常感謝您!它完美的工作! – dave