2013-10-14 3 views
0

많은 양의 행과 열로 구성된 Excel 파일에서 단어를 검색하는 매크로 바로 가기를 만들려고합니다. 원하는 단어를 검색 한 다음 프로그램에서 전체 행을 강조 표시 할 수있는 방법이 있습니까?Excel 2010에서 행 검색 및 강조 표시

enter image description here

답변

0

이 시도 :

Sub test() 

Dim rng, cel As Range 
Dim search_item 

Set rng = Selection 
search_item = InputBox("Find what?", "Test") 

For Each cel In rng 
    If cel.Value = search_item Then 
     cel.EntireRow.Select 
     Exit For 
    End If 
Next cel 

End Sub 

희망이 당신을 얻을 예를 들어

example

나는 "B"를 검색,이 같은 전체 행을 강조합니다 시작되었습니다.

업데이트 : 큰 행을 검색한다고 언급하셨습니다.
뿐만 아니라이를 사용할 수 있습니다 :

Sub test() 

Dim rng As Range 
Dim arr() As Variant 'i do not know your data type 
Dim search_item As Variant 'i do not know your data type, change to your liking 
Dim lrow, lcol As Long 
Dim found As Boolean 

Set rng = Selection 
lrow = rng.Rows.Count 
lcol = rng.Columns.Count 

ReDim arr(1 To lrow, 1 To lcol) 
arr = rng.Value 

search_item = InputBox("Find what?", "Test") 

For i = 1 To lrow 
    For j = 1 To lcol 
     If arr(i, j) = search_item Then 
      rng.Cells(i, j).EntireRow.Select 
      found = True 
      Exit For 
     End If 
    Next j 
    If found Then Exit For 
Next i 

End Sub 

두 코드는 당신이 원하는 않습니다.
현재 선택된 범위를 검색합니다.
큰 선택 항목을 검색 할 때 두 번째 코드가 더 빠릅니다.
또한 모두 일치 검색 만 찾습니다.

+0

내가 그것을 실행할 때 arr() 및 검색 항목을 문자열로 변경하고 디버깅 할 때 arr = rng.Value가 비어 있습니다. 왜 이렇게이다? 감사. – user2837847