여기에 추가 할 필요가없는 이유로 여러 셀에 텍스트가 포함 된 Excel 2007 스프레드 시트가 있습니다. 이 셀의 텍스트는 100 단어 미만에서 경우에 따라 거의 500 단어까지 다양합니다. 가끔씩 이러한 세포 중 일부에서 한 단어 를 찾아야 합니다.
이전에는 Excel의 검색 기능을 사용하여 단어가 포함 된 셀을 좁힌 후 눈으로 셀을 스캔했습니다. 이 작업을하는 동안 더 효율적인 방법이 있는지 궁금해졌습니다. 또한 더 많은 텍스트가 포함 된 셀로 작업하는 경우이 방법이 얼마나 지루하고 오류가 발생하기 쉬운 지 궁금해하기 시작했습니다. 즉, 복잡한 공식이나 VBA를 사용하지 않고 셀 내에서 검색을 수행하는 쉬운 방법이 있습니까?
물론, Word 문서에 텍스트를 복사하여 붙여넣고 Word에서 CTRL + F를 통해 단어를 정확하게 찾을 수 있지만 Excel의 셀 내에서 특정 단어를 간단히 검색하고 식별 할 수있는 쉬운 방법이 있습니까? 아래에이 영상을 붙여 넣었습니다.
위의 셀에서 눈으로이 셀을 스캔 한 후 "dispuestos"라는 단어를 강조 표시했습니다. Excel 검색 기능을 사용하여 쉽게 동일한 작업을 수행 할 수있는 방법이 있습니까? 예를 들어, Word 표에서 Tab 키를 사용하면 셀에서 셀로 이동할 수 있다는 것을 알고 있지만 셀 내에서 탭하려면 Ctrl + Tab을 누르기 만하면됩니다. Excel 셀 내에서 검색하는 데 사용할 수있는 유사한 기술이 있습니까? 이 작업을 수행하기 위해 Excel의 옵션을 변경해야합니까?
유일한 방법은 VBA라고 생각하고 있으므로이를 빠르게 달성 할 수있는 매크로 (... 죄송합니다)를 작성하는 규칙을 위반했습니다. 검색 용어의 모든 항목을 주황색으로 표시하고 찾은 항목 수를 알려줍니다. CTRL + SHIFT + F (특수 CTRL + F와 같은)와 같은 바로 가기를 만들 수 있습니다.
그건 그렇고, 선택이 진행되는 한 CTRL + F와 동일하게 작동합니다. 즉, 하나의 셀만 선택하면 전체 시트를 검색하지만 셀 범위를 선택하면 일반 찾기 기능과 마찬가지로 특정 범위 만 확인합니다.
다음은 결과의 예입니다.
다음은 VBA입니다.
Sub findPaintString()
Dim values As Range
Dim LastRow As Long, LastCol As Integer
myName = "Find+Paint String"
'We'll work like the normal Find/Replace function which looks at the selected range...
Set values = Selection
'...if the selected range is one cell then we look at the entire worksheet (within the used range):
If values.Cells.Count = 1 Then
LastRow = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
LastCol = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
Set values = Range(Cells(1, 1), Cells(LastRow, LastCol))
End If
'Set a suggested/default search query if you repeatedly search the same word:
strSearch = ""
'Get the string to paint:
theString = CStr(InputBox("Enter the string you want to paint" & vbNewLine & "(not case sensitive):", myName, strSearch))
If theString = "" Then Exit Sub
'Set the colour to paint occurrences:
theColour = 1137094
'Make a log of occurrences:
foundLog = 0
'Work through each cell in range, searching for the string and painting it:
For Each cell In values
'Check if our string is somewhere in the cell - if not then ignore it:
If InStr(LCase(cell.Value), LCase(theString)) Then
matchLog = 0 'match success log (increments by 1 per character)
j = 1 ' string character selector
For i = 1 To cell.Characters.Count
If LCase(Mid(cell.Value, i, 1)) = LCase(Mid(theString, j, 1)) Then
matchLog = matchLog + 1 '+1 to matchlog
j = j + 1 '+1 to string character selector
If matchLog = Len(theString) Then
'we have found the full word, so paint it:
cell.Characters(i - Len(theString) + 1, Len(theString)).Font.Color = theColour
j = 1 'reset string character ready for next use
matchLog = 0 'reset matchLog ready for next use
foundLog = foundLog + 1
End If
Else
'reset matchLog and string character selector:
matchLog = 0
j = 1
'see if this cell character (which didn't match the string character that we
'got up to) matches the first string character:
If LCase(Mid(cell.Value, i, 1)) = LCase(Mid(theString, j, 1)) Then
matchLog = matchLog + 1
j = j + 1
End If
End If
Next i
End If 'in string
Next cell
'Tidy data for message box:
If Len(theString) > 20 Then theString = Left(theString, 16) & "..."
If foundLog = 0 Then
foundLog = "0"
theS = "s"
ElseIf foundLog = 1 Then
theS = ""
Else
theS = "s"
End If
MsgBox "Found " & foundLog & " occurrence" & theS & " of '" & theString & "'.", vbOKOnly, myName
End Sub
대소 문자 를 구분합니다. 대소 문자를 구분하려면 LCase()
.
동일한 문자열을 자주 검색하는 경우 행 strSearch = ""
행을 [예] 로 변경하십시오 strSearch = "apples"
. 시작할 때 덮어 쓸 수 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다