编辑表功能只能正常工作

时间:2020-05-03 04:13:08

标签: excel vba excel-formula

我想做什么: 如果值类似于传递的条件,则更改表数据

代码:

Sub editTableData(tableName As String, rw As Integer, col As Integer, str As String)
    Sheet1.ListObjects(tableName).Range(rw, col).value = str
End Sub
Sub EDITTABLEDATAONOTHERPAGE()
    Call editTableData("statement", 20, 6, "Why did this work?")
End Sub 

结果:

03/19/2020, WAL-MART SUPERCENTER, 67.07, blank, blank, "Why did this work?"

enter image description here

但在此处调用时

Function categorize(criteria As String) As Double
    Dim statement As listobject, statementNames As Range, statementCategory As Range, statementCredit As Range, name As Range
    Set statement = Sheet1.ListObjects("statement")
    Set statementNames = Sheet1.ListObjects("statement").ListColumns("Name").DataBodyRange
    Set statementCategory = Sheet1.ListObjects("statement").ListColumns("Category").DataBodyRange
    Set statementCredit = Sheet1.ListObjects("statement").ListColumns("Credit").DataBodyRange
    '---this is the part that matters:--------------------------------
    For Each name In statementNames
        If name.value Like criteria + "*" Then
            Call editTableData(statement.name, name.row, statementCategory.column, statement.name)
            categorize = categorize + statementCredit(name.row, statementCredit.column).value
        End If
    Next
End Function

它进入方法,它将editTableData(“ statement”,20,6,“ statement”)分别作为String,int,int,String(所以相同的数据)传递给它,但是它只是停止工作,我也不知道为什么

任何启发性的都会很好,这是我正在使用该表调用公式的表:

桌子的图片

enter image description here


更新/修订: 这是调试照片: CALLING THE METHOD 在方法中(值的参考本地窗口): in the method

这一次再次按下F8时,它崩溃了... 没有错误消息,上方或下方的其他所有单元均未更改,因此根本无法正常工作。如果这是一个索引问题,将很容易解决

0 个答案:

没有答案