Excel VBA不匹配错误,正在编写公式

Excel VBA不匹配错误,正在编写公式,excel,vba,xlookup,Excel,Vba,Xlookup,我需要一些帮助。我需要帮助解决设置Plan=“LogInfo[Plan]”以及随后出现的不匹配错误。还需要帮助写一个公式,我写的excel在VBA格式 查找将从LogInfo到Design,在用户选择的单元格中显示从Design表到LogInfo的值 计划需要匹配计划,土壤报告需要匹配土壤报告,em和ym值都需要匹配以显示设计、bw、bd Sub WorkInProgress() ' ' Keyboard Shortcut: Ctrl+s ' Dim c As Range Di

我需要一些帮助。我需要帮助解决设置Plan=“LogInfo[Plan]”以及随后出现的不匹配错误。还需要帮助写一个公式,我写的excel在VBA格式

查找将从LogInfo到Design,在用户选择的单元格中显示从Design表到LogInfo的值

计划需要匹配计划,土壤报告需要匹配土壤报告,em和ym值都需要匹配以显示设计、bw、bd

Sub WorkInProgress()

'
' Keyboard Shortcut: Ctrl+s
'
    Dim c As Range
    Dim Plan As Range, Soils As Range, emC As Range, emE As Range, ymC As Range, ymE As Range               'dims for LogInfo Table/Worksheet
    Dim Plan1 As Range, Soils1 As Range, emC1 As Range, emE1 As Range, ymC1 As Range, _
    ymE1 As Range, design As Range, bw As Range, bd As Range                                                'dims for Design Table/Worksheet
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim ws1 As Worksheet
    
    Set wb = ThisWorkbook
    Set ws = wb.Worksheets("LogInfo")                   ' Table in this worksheet is also called "LogInfo"
    Set ws1 = wb.Worksheets("Design")                   ' Table in this worksheet is called "Design"
    
    Set Plan = "LogInfo[PLAN]"                          ' Col Header is called PLAN within the table
    Set Plan1 = "Design[PLAN]"                          ' Col Header is called PLAN within the table
    Set Soils = "LogInfo[SOILS REPORT]"                 ' Col Header is called SOILS REPORT within the table
    Set Soils1 = "Design[SOILS REPORT]"                 ' Col Header is called SOILS REPORT within the table
    Set emC = "LogInfo[em CENTER]"                      ' Col Header is called em CENTER within the table
    Set emC1 = "Design[em CENTER]"                      ' Col Header is called em CENTER within the table
    Set emE = "LogInfo[em EDGE]"                        ' Col Header is called em EDGE within the table
    Set emE1 = "Design[em EDGE]"                        ' Col Header is called em EDGE within the table
    Set ymC = "LogInfo[ym CENTER]"                      ' Col Header is called ym CENTER within the table
    Set ymC1 = "Design[ym CENTER]"                      ' Col Header is called ym CENTER within the table
    Set ymE = "LogInfo[ym EDGE]"                        ' Col Header is called ym EDGE within the table
    Set ymE1 = "Design[ym EDGE]"                        ' Col Header is called ym EDGE within the table
    Set design = "Design[Design]"                       ' Col Header is called Design within the table
    Set bw = "Design[BW]"                               ' Col Header is called BW within the table
    Set bd = "Design[BD]"                               ' Col Header is called BD within the table

    If Selection.Columns.Count > 1 Then
        MsgBox "Only select the cells you want numbered"
        Exit Sub
    End If

    For Each c In Selection
        If Not c.Rows.Hidden Then
            c.Value = Application.WorksheetFunction.XLookup()
            'I need help writing the formula above to match this
            '"=XLOOKUP(1,(Design!C[2]=[@PLAN]) * (Design!C[3]=[@[SOILS REPORT]]),Design!C[-4],""Needs To Be Designed"",0)"
            '
            '
            '
            '
        Else
            c.Clear
        End If
    Next c
End Sub

Dim LogInfo As ListObject
Set LogInfo=ws.ListObjects(“LogInfo”)
,然后
Set Plan=LogInfo.ListColumns(“Plan”).DataBodyRange
。或者
设置计划=范围(“LogInfo[Plan]”
。当前,右侧只是一个
字符串
,因此类型不匹配.c.Value=Application.WorksheetFunction.XLookup(1,Range(“B1:B3”)、Range(“C1:C3”)、“需要设计”,0)更容易设置所需的范围,或者如果是命名范围或表,则列本身的名称