2013-03-12 3 views
-1

열린 여러 통합 문서에서 문자열을 찾고 행을 색칠하는 방법. 문자열은 모든 시트에서 중복 될 수 있으며 A 열, B 열 또는 C 열에 나타날 수 있습니다.이 코드를 더 많은 통합 문서에 적용 할 수 있습니까? 나는 하나의 통합 문서에이 코드를 발견열린 여러 통합 문서에서 문자열 찾기

 Sub Search_String() 

    Dim SearchString As String 
    Dim SearchRange As Range, cl As Range 
    Dim Escolhe_Cor As Long 
    Dim FirstFound As String 
    Dim sh As Worksheet 

    ' Set Search value 
    SearchString = InputBox("Digite o número a ser procurado") 
    Escolhe_Cor = InputBox("Escolha uma cor para destacar esse número. De 3 a 56") 
    Application.FindFormat.Clear 
    ' loop through all sheets 
    For Each sh In ActiveWorkbook.Worksheets 
     ' Find first instance on sheet 
     Set cl = sh.Cells.Find(What:=SearchString, _ 
      After:=sh.Cells(1, 1), _ 
      LookIn:=xlValues, _ 
      LookAt:=xlPart, _ 
      SearchOrder:=xlByRows, _ 
      SearchDirection:=xlNext, _ 
      MatchCase:=False, _ 
      SearchFormat:=False) 
     If Not cl Is Nothing Then 
      ' if found, remember location 
      FirstFound = cl.Address 
      ' format found cell 
      Do 
       cl.EntireRow.Font.Bold = True 
       cl.EntireRow.Interior.ColorIndex = Escolhe_Cor 
       ' find next instance 
       Set cl = sh.Cells.FindNext(After:=cl) 
       ' repeat until back where we started 
      Loop Until FirstFound = cl.Address 
     End If 
    Next 
End Sub 
+0

질문을 계속하십시오 ... –

+0

안녕하세요,이 코드를 더 많은 통합 문서에 적용 할 수 있습니까? –

답변

1

그냥 루프 당신에게 현재의 코드를 추가해야처럼 사용자가 제공 한 정보가 보이는 무엇. 이렇게하면 열려있는 모든 통합 문서를 볼 수 있으므로이 옵션을 모두에 적용하지 않으려는 경우 통합 문서 이름을 식별하는 정규식을 사용할 수 있습니다.

For Each wb In Workbooks 
    'If you only want certain open workbooks searched use this If statement: 
    If wb.name = *criteria* Then 
     wb.Activate 
    'run your code that loops through each sheet 
    End If 
Next wb 
+0

고맙습니다. –

관련 문제