没有选择大小写错误的大小写编译错误

时间:2018-09-16 23:39:58

标签: excel vba

你好,我在代码的这一部分不断出现编译错误,找不到我所缺少的内容:

Case 5 ' Base oil specification changes?
    ' search datatbl for next empty row
    rw = data.Range.Rows.Count
    If rw = 2 Then
        If data.Range(rw, 1).Value = "" Then
        rw = 1
        Else
        data.Range(rw, 1).ListObject.ListRows.Add alwaysinsert:=True
        End If
    End If
    'populate the data table
    With data
    .Range(rw, 1).Offset(1) = Date
    .Range(rw, 2).Offset(1) = "A"
    .Range(rw, 3).Offset(1) = "Marketing"
    .Range(rw, 4).Offset(1) = Me.Controls("lblA" & i).Caption
    End With
    If Me.Controls("OptA" & i & "Y") = True Then
        With data
            .Range(rw, 5).Offset(1) = Me.Controls("OptA" & i & "Y").Caption
            .Range(rw, 6).Offset(1) = Me.Controls("txtA" & i).Value
            .Range(rw, 7).Offset(1) = "PLANT"
        End With
        'add data to summary table
        r = summary.Range.Rows.Count
        If r = 2 Then
            If summary.Range(r, 1).Value = "" Then
            r = 1
            Else
             summary.Range(r, 1).ListObject.ListRows.Add alwaysinsert:=True
            End If
        End If
        With summary
            .Range(r, 1).Offset(1) = Me.Controls("lblA" & i).Caption
            .Range(r, 2).Offset(1) = Me.Controls("OptA" & i & "Y").Caption
            .Range(r, 3).Offset(1) = Me.Controls("txtA" & i).Value
            .Range(r, 4).Offset(1) = "PLANT"
        End With
    ElseIf Me.Controls("OptA" & i & "N") = True Then
        data.Range(rw, 5).Offset(1) = Me.Controls("OptA" & i & "N").Caption
    End If

1 个答案:

答案 0 :(得分:1)

您需要添加Select Case才能使用Case方法,后跟要分析的对象。完成后,以End Select结尾。

下面的通用示例显示了如何实现Select Case的基础,其中要分析的对象是Range("A1")

Select Case Range("A1")
    Case 5
        'Do something if case is met
    Case Else
        'Do something is case is Else
End Select