Excel按钮问题

Excel按钮问题,excel,vba,Excel,Vba,我制作了一个非常简单的宏,在表的末尾添加一个列,其中包含串联的值,单击vba按钮时没有问题 但是,当我将宏指定给单独工作簿上的按钮时,会出现一个问题,即无法用正确的值填充所有行。(参见图中的黑色圆圈) 我的代码在下面 sub OrganizingResearchTracker() 'Variables Dim lr As Long lr = Cells.Find("*", Cells(1, 1), xlFormulas, xlPart,

我制作了一个非常简单的宏,在表的末尾添加一个列,其中包含串联的值,单击vba按钮时没有问题

但是,当我将宏指定给单独工作簿上的按钮时,会出现一个问题,即无法用正确的值填充所有行。(参见图中的黑色圆圈)

我的代码在下面

  sub OrganizingResearchTracker()
    
    'Variables
    Dim lr As Long
    lr = Cells.Find("*", Cells(1, 1), xlFormulas, xlPart, xlByRows, xlPrevious, False).Row
    
    Dim tbl As ListObject
    Dim wbNames As Variant, wb As Workbook, w As Workbook, El As Variant, boolFound As Boolean
    
      wbNames = Split("January,February,March,April,May,June,July,August,September,October,November,December", ",")
      For Each w In Workbooks
        For Each El In wbNames
            If w.Name = "Completed Research Docs_Tracker_" & El & " 2020.xlsm" Then
                Set wb = w: boolFound = True: Exit For
            End If
        Next
        If boolFound Then Exit For 'in order to stop iteration if a lot of workbooks are open
         Next
    
    '1. Column AB - Descriptive Field - Client Name - Manager Name - Research Deliverable
    
    wb.Activate
    Set tbl = ActiveSheet.ListObjects("Table_owssvr")
    With tbl
            .ListColumns.Add.Name = "Client Name - Manager Name - Research Deliverable"
    End With
    
        Range("AB2:AB" & lr).FormulaR1C1 = "=CONCATENATE(RC[-22],"" - "",RC[-26],"" - "",RC[-15])"
end sub

有人有这个问题,知道如何修正吗?谢谢

只需将公式写入您创建的
列表列的
.DataBodyRange
中就可以了

带tbl
...
.ListColumns(“客户名称-经理名称-研究成果”).DataBodyRange.FormulaR1C1=_
=串联(RC[-22]、“”-“”、RC[-26]、“”-“”、RC[-15])
以

尝试
.ListColumns(“客户名称-经理名称-研究成果”).DataBodyRange.FormulaR1C1=…
,在
中使用tbl
.perfect。感谢you@BigBen你知道为什么按钮会遇到这个问题吗?我猜lr不是你所期望的。但它在正常代码上工作,只是在我分配按钮时不起作用,奇怪