试图在用户窗体中使用 worksheetfunction?

Attempting to use worksheetfunction in userform?

我有一个自由格式的文本框,我想在上面的文本框 (txtStore) 中输入一个值后填充一个值<-基于 4 位数字。

这是我试过的代码,但不确定是否需要其他子(布尔逻辑)来触发某些东西?

Dim ws as worksheet
Private Sub txtMall_Change()
    Set ws = Worksheets("Lists")
    Dim txtStore As Integer: txtStore = Me.txtStore.Value
    txtMall.Value = Application.WorksheetFunction.IfError(VLookup(txtStore, ws.Range("A2:B1047", 2, False)), "-")
End Sub

在 txtStore 文本输入中放置一个值后,如何让 txtMall 根据该工作表函数进行填充?我是否需要像使用组合框那样将程序更改为其他程序?

未测试:

Private Sub txtStore_Change()
    Dim r
    'Avoid possible run-time error on no match by skipping WorksheetFunction
    '  Instead test the return value for errors 
    r = Application.VLookup(CLng(Me.txtStore.Value), _
                            Worksheets("Lists").Range("A2:B1047"), 2, False)
    txtMall.Value = IIf(iserror(r), "'-", r)
End Sub