使用 VBA 组合框返回值时类型不匹配使用 OR 语句? [重复]

问题描述 投票:0回答:0

VBA Excel:我正在尝试将用户表单中的数据写入我的工作表,并希望根据组合框中的值列表满足某些条件。如果它是一组值(通过使用 IF Combobox = "Value" OR "value" 识别,则从另一个文本框返回一个值。我收到运行时错误“13”类型不匹配。我将不胜感激任何帮助。可能有一种更聪明的方法可以做到这一点,但已经晚了,我得到了 VBA-eye lolz

'这是我的代码

Public Sub WriteDataToSheet1()
Dim rng As range
    
    If MsgBox("Are you sure you wish to add a new transaction ?", vbYesNo, "Add New Transaction") = vbYes Then
    
    Set rng = ActiveSheet.ListObjects(5).range
    Dim LastRow As Long
    Dim DateValue As Date
    LastRow = rng.Find(What:="*", _
    After:=rng.Cells(1), _
    Lookat:=xlPart, _
    LookIn:=xlFormulas, _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlPrevious, _
    MatchCase:=False).row

    
        
            ActiveSheet.ListObjects(5).ListRows.Add AlwaysInsert:=True
            rng.Parent.Cells(LastRow + 1, 1).Value = ComboBoxTransactionType.Value
            rng.Parent.Cells(LastRow + 1, 2).Value = TextBoxReference.Value
            DateValue = CDate(TextBoxDate.Value)
            rng.Parent.Cells(LastRow + 1, 3).Value = Format(DateValue, "DD-MMM-YYYY")
            DateValue = CDate(TextBoxEndDate.Value)
            rng.Parent.Cells(LastRow + 1, 4).Value = Format(DateValue, "DD-MMM-YYYY")
            rng.Parent.Cells(LastRow + 1, 5).Value = ComboBoxFrequency.Value
            If ComboBoxTransactionType = "Payment" Or "Fee" Or "Contingency Fee" Or "penalty" Then rng.Parent.Cells(LastRow + 1, 6).Value = TextBoxAmount.Value
            If ComboBoxTransactionType = "Partial repayment" Or "Full Repayment" Or "Interest Waived" Or "forebearance" Or "Interest freeze" Or "refund" Or "Interest write off" Or "Fees write off" Or "Capital Write Off" Then rng.Parent.Cells(LastRow + 1, 7).Value = TextBoxAmount.Value
excel vba if-statement combobox userform
© www.soinside.com 2019 - 2025. All rights reserved.