Excel VBA에서 Application.Match를 사용하여 대 / 소문자 구분 일치를 얻으려고합니다.
INDEX 및 MATCH 및 EXACT를 사용하여 수식을 참조하는 많은 게시물을 읽었지만 VBA에서 작동하려면 이것이 필요합니다 ... WorksheetFunction.Match를 사용하여 운이 없었습니다. 여기에 사례를 만들기 위해 수정해야하는 코드가 있습니다. 민감한. 미리 감사드립니다
Sub Validate_Values2()
Dim i As Long, f As Variant
With Worksheets("Company")
For i = 2 To .Cells(.Rows.Count, "M").End(xlUp).Row
f = Application.Match(.Cells(i, "M").Value2, Worksheets("Lookups").Columns("U"), 0)
If IsError(f) Then
.Cells(i, "M").Interior.ColorIndex = 33
End If
Next i
End With
End Sub
VBA의 직접 문자열 대 문자열 비교는 vbBinaryCompare에서 대소 문자를 구분합니다. VBA가 기본적으로 필터 기능에 대한 답을 가지고 있는데 왜 잘못된 워크 시트 기능을 의도대로 구부리려고 합니까?
Option Explicit
Sub Validate_Values3()
Dim i As Long, f As Long, comps As Variant, lookups As Variant
With Worksheets("Lookups")
'skips a header row in Lookups!:U:U
'creates a zero-based 1-D array
lookups = Application.Transpose(.Range(.Cells(2, "U"), .Cells(.Rows.Count, "U").End(xlUp)).Value2)
End With
With Worksheets("Company")
'skips a header row in Company!:M:M
'creates a one-based 2-D array
comps = .Range(.Cells(2, "M"), .Cells(.Rows.Count, "M").End(xlUp)).Value2
For i = LBound(comps, 1) To UBound(comps, 1)
'Debug.Print comps(i, 1) & " " & UBound(Filter(lookups, comps(i, 1), True, vbBinaryCompare))
f = UBound(Filter(lookups, comps(i, 1), True, vbBinaryCompare))
If f < 0 Then
'shift down one row to account for skipped header
.Cells(i + 1, "M").Interior.ColorIndex = 33
End If
Next i
End With
End Sub
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다