셀 C3에서 사용자 입력을 할 때 완벽하게 작동하는 기존 코드가 있으며 그 아래에있는 데이터 테이블을 검색하고 상단에 제품 코드에 대한 모든 일치하는 결과를 깔끔하게 표시합니다 행이 거의 없습니다. 이 코드를 업데이트하여 정확한 일치 항목을 찾을 수없는 이벤트의 일부 로직을 포함해야하지만 비슷한 일치 항목을 발견했을 수 있습니다. 정확하게 일치가 발견되지 않는 경우정확히 일치하는 루프를 반환하지만 유사한 일치를 반환하도록 업데이트해야합니다
Option Compare Text
Sub MultipleLkp()
Dim numRows As Integer, numCols As Integer, i As Integer, j As Integer, k As Integer, PrimKey, lastColumn As Long
Dim Trimkey As String
Application.ScreenUpdating = False
Worksheets("DashboardMain").Range("D3:R8").ClearContents
Worksheets("DashboardMain").Range("C200").CurrentRegion.Select
PrimKey = Worksheets("DashboardMain").Range("C3").Value
numRows = Selection.Rows.Count
numCols = Selection.Columns.Count
j = 2
lastColumn = Cells.Find(What:="*", After:=Range("A1"), Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False).Column
'TrimKey is the variable replacing PrimKey but without spaces or hyphens.
'allows user to input a model with or without " " or "-" in cell C3
'can be modified to include more invalid characters
Trimkey = Replace(Replace(PrimKey, " ", ""), "-", "")
If Trimkey = "" Then
Exit Sub
End If
'runs the loop and returns all matches; displays matches in rows 3 down until all matches found
'does not have any logic if no match is found. need to add the "like" function?
For i = 2 To numRows
If Worksheets("DashboardMain").Cells(199 + i, 3).Value = Trimkey Then
j = j + 1
For k = 1 To lastColumn
Worksheets("DashboardMain").Cells(j, 3 + k).Value = Worksheets("DashboardMain").Cells(199 + i, 3 + k).Value
Next k
End If
Next I
end sub
이상적으로, 메시지 상자가 가능한 일치를 보여 것이라고 표시 할 다음 사용자가 잠재적 인 일치를 선택할 수 있습니다, 다음으로 같은 지역에 따라 표시 할 것입니다 : 여기에 기존의 코드는 정확히 일치하는 것처럼 어떤 도움도 감사하겠습니다.
나는 이것을 줄 것이다. 그래서이 코드를 자체 모듈에 붙여 넣으면 기존의 LEVEN이라는 공용 함수를 호출 할 수 있습니까? 이게 어떻게 작동하는거야? –
. 이것은 솔루션을 사용할 준비가되지 않았지만, 이것을 사용하여 코드를 수정할 수 있어야합니다. – MarcinSzaleniec
올바르게 이해하면 LEVEN 함수는 2 개의 문자열이 일치하도록 문자 편집 횟수를 반환합니다. 2 개의 문자열은 사용자 입력이고 데이터 테이블의 잠재적 인 유사한 일치입니다. LEVEN이 <3이라고 말하면 결과를 반환하도록 매개 변수를 설정할 수 있습니다. 문자열이 비슷하지만 3자를 편집해야 정확한 결과를 얻을 수 있습니다 ... 또한 입력 해 주셔서 감사합니다. 이것은 매우 도움이된다. –