퍼지 조회 추가 기능이 결과를 임의 위치에 붙여 넣습니다.


4

"Excel 용 퍼지 조회 추가 기능"은 여기에서 볼 수 있습니다 .

나는 이름 (약간)과 위치 모두에서 계속 바뀌는 많은 "헤더"를 얻는다. 퍼지 매칭 토지로 이번에는 물건이 어디에 있는지, 무엇을 불렀는지 알아 내십시오. 퍼지 매치를 처음 실행하면 작동합니다! 그림과 같이 세부 정보를 얻습니다. 로 표시된 표 Headers가 소스이고로 표시된 표 Matching에 결과 가 포함되어 있습니다.

그러나 다시 실행하면 그림과 같이 결과가 오른쪽 아래에 나타납니다. 왜 그런 겁니까? 이 문제가 발생하는 것을 방지하고 데이터가 원하는 위치에서 일관되게 끝나도록하려면 어떻게해야합니까?

(예, '할인'이 두 번째로 '총 할인 마이너스 할인'과 일치하지 않아야 함을 알 수 있습니다. 비워 두어야합니다. 설정을 조정하여 해결할 수 있습니다.)

오류 사진


"다시 실행할 때"라고 말할 때 수행 한 정확한 단계를 설명 할 수 있습니까?
— Floris

확실한. "Go"(오른쪽 아래)를 누르면 테이블에 Headers and Similarity가 추가됩니다. 좋은. "이동"을 다시 한 번 누릅니다. 그러면 추가 / 잘못된 데이터가 추가됩니다. 설정 중 아무것도 변경하지 않았으며 어느 테이블에서도 아무것도 변경되지 않았습니다.
— Selkie

"히팅"중이라면 대화 상자가 있다는 의미입니다. 대화 상자의 필드는 무엇입니까? 입력 / 출력 범위를 선택합니까?
— Floris

그림에서 잘린 것처럼 보입니다-오른쪽 퍼지 조회 대화 상자의 맨 아래에 있습니다. 퍼지 조회 상자는 사용한 후에도 동일한 설정으로 열려 있습니다.
— Selkie

답변:


1

Fuzzy Lookup추가 기능을 직접 스크립팅 할 수는 없지만 대부분의 버그와 문제를 해결할 수있었습니다.

다음 코드는 Workbook_SheetChangeand Workbook_SheetSelectionChange이벤트를 사용하여 활성 셀의 위치에 관계없이 지정된 테이블에 대한 출력 위치를 "잠금" 합니다.

'============================================================================================
' Module     : ThisWorkbook
' Version    : 1.0
' Part       : 1 of 1
' References : N/A
' Source     : https://superuser.com/a/1283003/763880
'============================================================================================
Option Explicit

Private Const s_FuzzyLookupResultsTable As String = "MatchingTable"
Private Const RESTORE_SELECTION As Boolean = True

Private Sub Workbook_SheetChange _
            ( _
                       ByVal TheWorksheet As Object, _
                       ByVal Target As Range _
            )
        Dim Ä As Excel.Application: Set Ä = Excel.Application
        Dim ƒ As Excel.WorksheetFunction: Set ƒ = Excel.WorksheetFunction

  Const l_FuzzyLookup_AddIn_Undo_Sheet As String = "FuzzyLookup_AddIn_Undo_Sheet"
  Const s_InCell_Error_Message As String = "SAVE, CLOSE & REOPEN if pressing GO again doesn't fix it"

  Static swkstActiveFuzzyLookupSheet As Worksheet
  Static sstrOriginalSelection As String

  Select Case True
    Case TheWorksheet.Name <> l_FuzzyLookup_AddIn_Undo_Sheet And swkstActiveFuzzyLookupSheet Is Nothing:
      Exit Sub
    Case TheWorksheet.Name = l_FuzzyLookup_AddIn_Undo_Sheet And swkstActiveFuzzyLookupSheet Is Nothing:
      'TODO If missing table
      Set swkstActiveFuzzyLookupSheet = ActiveSheet
      sstrOriginalSelection = Selection.Address
    Case TheWorksheet.Name = l_FuzzyLookup_AddIn_Undo_Sheet And Not swkstActiveFuzzyLookupSheet Is Nothing:
      With swkstActiveFuzzyLookupSheet.ListObjects(s_FuzzyLookupResultsTable)
        Ä.EnableEvents = False
          ' This is a Fuzzy Lookup bug work-around to show an in-cell error if the output doesn't update
          If .ListColumns.Count > 1 Then
            Dim strHeaderRowRange As String: strHeaderRowRange = .HeaderRowRange.Address
            Dim varHeaders() As Variant: varHeaders = ƒ.Transpose(ƒ.Transpose(.HeaderRowRange.Value2))
            With Range(.ListColumns(2).DataBodyRange, .ListColumns(.ListColumns.Count).DataBodyRange)
              Dim strDeletedRange As String: strDeletedRange = .Address
              .Delete
            End With
            Range(strDeletedRange).Insert Shift:=xlToRight
            Range(strDeletedRange).Value2 = s_InCell_Error_Message
            Range(strHeaderRowRange).Value2 = varHeaders
          End If
          ' This is the magic line that forces the output back into the table
          .HeaderRowRange.Cells(1).Select
        Ä.EnableEvents = True
      End With
    Case TheWorksheet.Name = swkstActiveFuzzyLookupSheet.Name:
      With swkstActiveFuzzyLookupSheet.ListObjects(s_FuzzyLookupResultsTable).Range
        If Target.Cells(Target.Cells.Count).Address = .Cells(.Cells.Count).Address Then
          ' <optional>
          ' Only restore the selection if set to do so and the selection is not the first header cell
          If RESTORE_SELECTION _
          And sstrOriginalSelection <> .Cells(1).Address _
          Then
            Ä.EnableEvents = False
              Range(sstrOriginalSelection).Select
            Ä.EnableEvents = True
            ' Unfortunately the above Select doesn't stick. The Add-in trys to change the selection another 1 or 2 times.
            ' The following hack is required so that the Workbook_SheetSelectionChange handler can revert these attempts.
            ' Note that if the original selection contains the first header cell, only 1 attempt is made. Otherwise it makes 2 attempts.
            RevertSelection _
              RevertTo:=Selection, _
              NumberOfTimes:=IIf(Intersect(Selection, .Cells(1)) Is Nothing, 2, 1)
          End If
          ' </optional>
          sstrOriginalSelection = vbNullString
          Set swkstActiveFuzzyLookupSheet = Nothing
        End If
      End With
    Case Else:
      Exit Sub
   'End Cases
  End Select

End Sub

' The following code is only needed if the RESTORE_SELECTION option is required.
' If the code is removed, the optional code in the Workbook_SheetChange handler above also needs to be removed.

Private Sub RevertSelectionIfRequired()
  RevertSelection
End Sub

Private Sub RevertSelection _
            ( _
              Optional ByRef RevertTo As Range, _
              Optional ByRef NumberOfTimes As Long _
            )

  Static srngRevertTo As Range
  Static slngRevertCount As Long

  Select Case True
    Case Not RevertTo Is Nothing:
      Set srngRevertTo = RevertTo
      slngRevertCount = NumberOfTimes
    Case Not srngRevertTo Is Nothing:
      With Application
        .EnableEvents = False
        srngRevertTo.Select
        .EnableEvents = True
      End With
      slngRevertCount = slngRevertCount - 1
      If slngRevertCount = 0 Then Set srngRevertTo = Nothing
    Case Else:
      Exit Sub
   'End Cases
  End Select

End Sub

Private Sub Workbook_SheetSelectionChange _
            ( _
                       ByVal TheWorksheet As Object, _
                       ByVal Target As Range _
            )

  RevertSelectionIfRequired

End Sub

잠을자는 후에 버그, 이슈 및주의 사항에 대해 더 많은 정보를 추가 할 것입니다 ;-)
— robinCTS

3

활성 셀에서 시작하여 테이블이 출력됩니다. 따라서 "GO"를 클릭하기 전에 왼쪽 위 모서리 셀을 클릭하여 테이블을 원하는 위치를 선택해야합니다.


매크로 레코더보다 직접 객체 참조를 사용하도록 응답을 편집 할 수 있습니까?
— Selkie

나는 당신이 무엇을 요구하는지 명확하지 않습니다.
— HackSlash

불행하게도, 퍼지 매칭이 실행될 때 매크로 레코더는 아무것도 뱉어 내지 않습니다.
— Selkie

외부 플러그인이기 때문에 스크립트로 작성하지 못할 수도 있습니다 .... 답변을 수정하겠습니다
— HackSlash
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.