반응형
vba code Cells에서 Excel 열의 값을 찾는 방법.검색
엑셀 시트에서 가치 있는 셀다를 찾아야 합니다.이 vba 코드를 사용하여 찾았습니다.
Set cell = Cells.Find(What:=celda, After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False)
If cell Is Nothing Then
'do it something
Else
'do it another thing
End If
문제는 엑셀란에서만 값을 찾아야 하는 경우입니다.다음 코드와 함께 찾습니다.
Columns("B:B").Select
Selection.Find(What:="VA22GU1", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
하지만 첫 번째 vba 코드에 적응하는 방법을 모릅니다. 왜냐하면 값을 사용해야 하기 때문입니다.nothing
.
그냥 사용하다
Dim Cell As Range
Columns("B:B").Select
Set cell = Selection.Find(What:="celda", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If cell Is Nothing Then
'do it something
Else
'do it another thing
End If
완성도를 높이기 위해 엑셀 테이블에서도 위와 같은 기술을 사용할 수 있습니다.
다음 예제에서는 "tblConfig"라는 이름의 Excel 테이블의 셀에 보통 숨겨져 있는 Config라는 이름의 시트에 텍스트를 표시하고 있습니다.Find(찾기) 메서드의 기본값을 사용합니다.
Dim list As ListObject
Dim config As Worksheet
Dim cell as Range
Set config = Sheets("Config")
Set list = config.ListObjects("tblConfig")
'search in any cell of the data range of excel table
Set cell = list.DataBodyRange.Find(searchTerm)
If cell Is Nothing Then
'when information is not found
Else
'when information is found
End If
를 사용하고 싶습니다..Find
검색할 셀의 범위를 포함하는 범위 개체에서 직접 메서드를 지정합니다.원본 포스터의 코드의 경우 다음과 같습니다.
Set cell = ActiveSheet.Columns("B:B").Find( _
What:=celda, _
After:=ActiveCell _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False _
)
If cell Is Nothing Then
'do something
Else
'do something else
End If
변수를 더 많이 사용하고(및 반드시 선언해야 함) 많은 선택적 인수가 기본값을 사용하도록 합니다.
Dim rng as Range
Dim cell as Range
Dim search as String
Set rng = ActiveSheet.Columns("B:B")
search = "String to Find"
Set cell = rng.Find(What:=search, LookIn:=xlFormulas, LookAt:=xlWhole, MatchCase:=False)
If cell Is Nothing Then
'do something
Else
'do something else
End If
나는 계속했다LookIn:=
,LookAt::=
,그리고.MatchCase:=
어떤 것이 일치하는지 명확하게 할 수 있습니다.기타 옵션 파라미터는 주문 일치가 반환되는 순서를 제어합니다.주문이 어플리케이션에 중요한 경우에만 지정합니다.
Dim strFirstAddress As String
Dim searchlast As Range
Dim search As Range
Set search = ActiveSheet.Range("A1:A100")
Set searchlast = search.Cells(search.Cells.Count)
Set rngFindValue = ActiveSheet.Range("A1:A100").Find(Text, searchlast, xlValues)
If Not rngFindValue Is Nothing Then
strFirstAddress = rngFindValue.Address
Do
Set rngFindValue = search.FindNext(rngFindValue)
Loop Until rngFindValue.Address = strFirstAddress
언급URL : https://stackoverflow.com/questions/14931700/how-to-find-a-value-in-an-excel-column-by-vba-code-cells-find
반응형
'programing' 카테고리의 다른 글
Xcode 6에서 생성되지 않은 목표 C 헤더로 빠르게 이동 (0) | 2023.04.22 |
---|---|
Bash 루프의 카운터 증분이 작동하지 않음 (0) | 2023.04.22 |
Windows에서 Git Bash를 사용할 때 개인 키를 해독하기 위한 패스워드가 매번 입력되지 않도록 하려면 어떻게 해야 합니까? (0) | 2023.04.22 |
WPF에 Design Mode 속성이 있습니까? (0) | 2023.04.22 |
시스템 추가 중Web.클래스 라이브러리의 스크립트 참조 (0) | 2023.04.22 |