0

我想将来自三个不同下拉列表的数据插入到我的电子表格中,但我遇到了一些困难。共有三个下拉菜单,称为cbo_fac1cbo_fac2cbo_fac3。以下是用例:

用例 1

cbo_fac1 - User selects 'No Preference' 
cbo_fac2 - User selects 'No Preference' 
cbo_fac3 - User selects 'No Preference' 

在这种情况下,我只想将 No Preference 插入到电子表格单元格中。到目前为止,这件事处理得很好。

用例 2 和 3

cbo_fac1 - User does not select 'No Preference' 
cbo_fac2 - User does not select 'No Preference' 
cbo_fac3 - User selects 'No Preference' 

cbo_fac1 - User does not select 'No Preference' 
cbo_fac2 - User selects 'No Preference' 
cbo_fac3 - User selects 'No Preference' 

在这两种情况下,我都希望 'No Preference 被跳过,只有那些不No Preference被插入的值。

我已经尝试过了,但不幸的是系统插入了我想省略的逗号。因此,我不想拥有类似的条目,PC,DVD,或者,DVD,PC如果用户选择了该No Preference选项,我想整理它并让它看起来像PC, DVDDVD, PC删除与空白条目关联的逗号。

我希望我的解释足够清楚,我在下面包含了代码来展示我到目前为止所完成的工作。

 If Me.cbo_fac1 <> "No preference" Then
    cbo_fac1Entry = Me.cbo_fac1.Value
    Else
    cbo_fac1Entry = ""
    End If
    If Me.cbo_fac2 <> "No preference" Then
    cbo_fac2Entry = Me.cbo_fac2.Value
    Else
    cbo_fac2Entry = ""
    End If
    If Me.cbo_fac3 <> "No preference" Then
    cbo_fac3Entry = Me.cbo_fac3.Value
    Else
    cbo_fac3Entry = ""
    End If

    cbo_facEntry = cbo_fac1Entry & "," & cbo_fac2Entry & "," & cbo_fac3Entry

    If cbo_facEntry = ",," Then
    cbo_facEntry = "No Preference"
    Else
    End If

    rng1.Offset(1, 13) = cbo_facEntry
4

1 回答 1

1

If cbo_facEntry = ",," Then
cbo_facEntry = "No Preference"
Else
End If

我会插入

cbo_facEntry = Trim(cbo_facEntry)

If Right(cbo_facEntry, 1) = "," Then
   cbo_facEntry = Left(cbo_facEntry, Len(cbo_facEntry) - 1)
End If

If Left(cbo_facEntry, 1) = "," Then
   cbo_facEntry = Right(cbo_facEntry, Len(cbo_facEntry) - 1)
End If

If InStr(1, cbo_facEntry, ",,") Then
   cbo_facEntry = Replace(cbo_facEntry, ",,", ", ")
End If

封面案例“,DVD,,PC,”

于 2012-10-30T09:44:27.667 回答