0

整整一周,我与几个具有 VB 经验的人一起工作,但我们无法让所有这些 If / Then 语句正常工作。除引用“otype”+ SCE+ CNE 和“otype”= 专线或仅 Internet 的语句外,所有语句均有效。逻辑似乎是正确的,但我们没有得到预期的结果。帮助!下面是我们有疑问的VB代码。谢谢你。

Private Sub Worksheet_Activate()

End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

    Rem CNE Customer
    If Range("otype") = "SCE+ CNE" Then
        Worksheets("VNC Form").Visible = True
        Worksheets("ISC Portal").Visible = True
        Worksheets("ISC Request Only").Visible = False
        Worksheets("VPN Details").Visible = False

    Else
        Worksheets("VNC Form").Visible = False
        Worksheets("ISC Portal").Visible = False
    End If

    Rem ISM ABC Customer
    If Range("otype") = "SC4ABC" Then
        Worksheets("ISM-ABC Customers").Visible = True
        Worksheets("ISM Portal").Visible = True

    Else
        Worksheets("ISM-ABC Customers").Visible = False
    End If


    Rem VPN Details tab
    If Range("ctype") = "VPN" Then
        Worksheets("VPN Details").Visible = True
        Worksheets("ISC Portal").Visible = True
        Worksheets("VNC Form").Visible = False

    Else
        Worksheets("VPN Details").Visible = False
        Worksheets("ISC Portal").Visible = False
        Worksheets("VNC Form").Visible = False
    End If

    Rem Connections tabs
    If Range("ctype") = "Dedicated Line" Or Range("ctype") = "Internet Only" Then
        Worksheets("ISC Portal").Visible = True
        Worksheets("VPN Details").Visible = False

    Else
        Worksheets("ISC Portal").Visible = False
        Worksheets("VPN Details").Visible = False
    End If

    Rem AT&T and Connection tabs
    If Range("otype") = "SCE+ Reseller" And Range("ctype") = "CNE" Or Range("otype") = "SCE+ Internal" And Range("ctype") = "CNE" Then
        Worksheets("ISC Request Only").Visible = True
        Worksheets("VNC Form").Visible = True
        Worksheets("ISC Portal").Visible = False
        Worksheets("VPN Details").Visible = False

    Else
        Worksheets("ISC Request Only").Visible = False
        Worksheets("VNC Form").Visible = False
        Worksheets("ISC Portal").Visible = True
        Worksheets("VPN Details").Visible = True
    End If

End Sub
4

1 回答 1

0

虽然我下面的代码可能会有所帮助,但我建议使用 QAT 上的下拉菜单或功能区上的按钮来允许用户决定要取消隐藏/隐藏哪些工作表。每次修改工作表中的任何单元格时,您的代码都会运行。

正如 Sid 所建议的那样,可能值得将您的代码包含在 CASE 语句中,以便仅在 Target= otype 或 ctype 时运行...

也许尝试强制案例,并强制空格为零,如下所示:

Rem CNE Customer  

If Trim(UCase(replace(Range("otype").TEXT," ",""))) = "SCE+CNE" Then  
    Worksheets("VNC Form").Visible = True
    Worksheets("ISC Portal").Visible = True
    Worksheets("ISC Request Only").Visible = False
    Worksheets("VPN Details").Visible = False

Else
    Worksheets("VNC Form").Visible = False
    Worksheets("ISC Portal").Visible = False
End If

Rem Connections tabs
If (TRIM(UCase(replace(Range("ctype")," ",""))) = "DEDICATEDLINE") Or (TRIM(UCASE(REPLACE(Range("ctype")," ",""))) = "INTERNETONLY") Then
    Worksheets("ISC Portal").Visible = True
    Worksheets("VPN Details").Visible = False

Else
    Worksheets("ISC Portal").Visible = False
    Worksheets("VPN Details").Visible = False
End If

Rem AT&T and Connection tabs
If (TRIM(UCase(replace(Range("otype")," ",""))) = "SCE+RESELLER" And TRIM(UCase(replace(Range("ctype")," ",""))) = "CNE") Or (TRIM(UCase(replace(Range("otype")," ",""))) = "SCE+INTERNAL" And TRIM(UCase(replace(Range("ctype")," ",""))) = "CNE") Then
    Worksheets("ISC Request Only").Visible = True
    Worksheets("VNC Form").Visible = True
    Worksheets("ISC Portal").Visible = False
    Worksheets("VPN Details").Visible = False

Else
    Worksheets("ISC Request Only").Visible = False
    Worksheets("VNC Form").Visible = False
    Worksheets("ISC Portal").Visible = True
    Worksheets("VPN Details").Visible = True
End If
于 2013-04-25T08:45:12.347 回答