Microsoft Excel VBA-运行时错误438

时间:2018-07-02 09:16:57

标签: excel vba excel-vba runtime-error

我似乎有一个错误,我正在努力找出原因。我尝试过帮助部分,也尝试过在线研究它,但是没有得出任何结果。我希望有人可以在这件事上为我提供帮助。

问题

我为电子表格上的不同工作表创建了多个表单。我制作了一些表单,可以根据用户的判断来隐藏/显示选择的列。我有两种形式都可以很好地工作,但是第三种形式。

我知道

  

运行时错误438“对象不支持此属性或方法”

这是什么意思?该代码与其他形式完全相同。它们之间的唯一区别是工作表的名称不同。

我将在下面粘贴工作表的代码。希望您可以区分哪个。我会尽力解释。

下面的代码

主表-包含用于打开表单的按钮

Private Sub openUserForm_Click()
    chkFormCooms.Show
End Sub

用户表单

Option Explicit

Sub hideCol(C As Integer)
    If Controls("CheckBox" & C) = True Then
        Columns(C).Hidden = True
    Else
        Columns(C).Hidden = False
    End If
    ActiveWindow.ScrollColumn = 1
End Sub

Private Sub chkP1_Click()
    If Me.chkP1.Value = True Then
        Sheets("Cooms").Columns("T:W").Hidden = True
        Sheets("chkCooms").chk1.Value = True
    ElseIf Me.chkP1.Value = False Then
        Sheets("Cooms").Columns("T:W").Hidden = False
        Sheets("chkCooms").chk1.Value = False
    End If
End Sub

Private Sub chkP2_Click()
    If Me.chkP2.Value = True Then
        Sheets("Cooms").Columns("X:AA").Hidden = True
        Sheets("chkCooms").chk2.Value = True
    ElseIf Me.chkP2.Value = False Then
        Sheets("Cooms").Columns("X:AA").Hidden = False
        Sheets("chkCooms").chk2.Value = False
    End If
End Sub

Private Sub chkP3_Click()
   If Me.chkP3.Value = True Then
        Sheets("Cooms").Columns("AB:AE").Hidden = True
        Sheets("chkCooms").chk3.Value = True
    ElseIf Me.chkP3.Value = False Then
        Sheets("Cooms").Columns("AB:AE").Hidden = False
        Sheets("chkCooms").chk3.Value = False
    End If
End Sub

Private Sub chkP4_Click()
    If Me.chkP4.Value = True Then
        Sheets("Cooms").Columns("AF:AI").Hidden = True
        Sheets("chkCooms").chk4.Value = True
    ElseIf Me.chkP4.Value = False Then
        Sheets("Cooms").Columns("AF:AI").Hidden = False
        Sheets("chkCooms").chk4.Value = False
    End If
End Sub

Private Sub chkP5_Click()
   If Me.chkP5.Value = True Then
        Sheets("Cooms").Columns("AJ:AM").Hidden = True
        Sheets("chkCooms").chk5.Value = True
    ElseIf Me.chkP5.Value = False Then
        Sheets("Cooms").Columns("AJ:AM").Hidden = False
        Sheets("chkCooms").chk5.Value = False
    End If
End Sub

Private Sub chkP6_Click()
    If Me.chkP6.Value = True Then
        Sheets("Cooms").Columns("AN:AQ").Hidden = True
        Sheets("chkCooms").chk6.Value = True
    ElseIf Me.chkP6.Value = False Then
        Sheets("Cooms").Columns("AN:AQ").Hidden = False
        Sheets("chkCooms").chk6.Value = False
    End If
 End Sub

Private Sub chkP7_Click()
    If Me.chkP7.Value = True Then
        Sheets("Cooms").Columns("AR:AU").Hidden = True
        Sheets("chkCooms").chk7.Value = True
    ElseIf Me.chkP7.Value = False Then
        Sheets("Cooms").Columns("AR:AU").Hidden = False
        Sheets("chkCooms").chk7.Value = False
    End If
End Sub

Private Sub chkP8_Click()
    If Me.chkP8.Value = True Then
        Sheets("Coomst").Columns("AV:AY").Hidden = True
        Sheets("chkCooms").chk8.Value = True
    ElseIf Me.chkP8.Value = False Then
        Sheets("Cooms").Columns("AV:AY").Hidden = False
        Sheets("chkCooms").chk8.Value = False
    End If
End Sub

Private Sub chkP9_Click()
    If Me.chkP9.Value = True Then
        Sheets("Cooms").Columns("AZ:BC").Hidden = True
        Sheets("chkCooms").chk9.Value = True
    ElseIf Me.chkP9.Value = False Then
        Sheets("Cooms").Columns("AZ:BC").Hidden = False
        Sheets("chkCooms").chk9.Value = False
    End If
End Sub

 Private Sub chkP10_Click()
    If Me.chkP10.Value = True Then
        Sheets("Cooms").Columns("BD:BG").Hidden = True
        Sheets("chkCooms").chk10.Value = True
    ElseIf Me.chkP10.Value = False Then
        Sheets("Cooms").Columns("BD:BG").Hidden = False
        Sheets("chkCooms").chk10.Value = False
    End If
End Sub

 Private Sub chkP11_Click()
    If Me.chkP11.Value = True Then
        Sheets("Cooms").Columns("BH:BK").Hidden = True
        Sheets("chkCooms").chk11.Value = True
    ElseIf Me.chkP11.Value = False Then
        Sheets("Cooms").Columns("BH:BK").Hidden = False
        Sheets("chkCooms").chk11.Value = False
    End If
End Sub

 Private Sub chkP12_Click()
    If Me.chkP12.Value = True Then
        Sheets("Cooms").Columns("BL:BO").Hidden = True
        Sheets("chkCooms").chk12.Value = True
    ElseIf Me.chkP12.Value = False Then
        Sheets("Cooms").Columns("BL:BO").Hidden = False
        Sheets("chkCooms").chk12.Value = False
    End If
End Sub

 Private Sub chkP13_Click()
    If Me.chkP13.Value = True Then
        Sheets("Cooms").Columns("BP:BS").Hidden = True
        Sheets("chkCooms").chk13.Value = True
    ElseIf Me.chkP13.Value = False Then
        Sheets("Cooms").Columns("BP:BS").Hidden = False
        Sheets("chkCooms").chk13.Value = False
    End If
End Sub

Private Sub UserForm_Initialize()
    Me.chkP1.Value = Sheets("chkCooms").chk1.Value
    Me.chkP2.Value = Sheets("chkCooms").chk2.Value
    Me.chkP3.Value = Sheets("chkCooms").chk3.Value
    Me.chkP4.Value = Sheets("chkCooms").chk4.Value
    Me.chkP5.Value = Sheets("chkCooms").chk5.Value
    Me.chkP6.Value = Sheets("chkCooms").chk6.Value
    Me.chkP7.Value = Sheets("chkCooms").chk7.Value
    Me.chkP8.Value = Sheets("chkCooms").chk8.Value
    Me.chkP9.Value = Sheets("chkCooms").chk9.Value
    Me.chkP10.Value = Sheets("chkCooms").chk10.Value
    Me.chkP11.Value = Sheets("chkCooms").chk11.Value
    Me.chkP12.Value = Sheets("chkCooms").chk12.Value
    Me.chkP13.Value = Sheets("chkCooms").chk13.Value
End Sub

我希望这一切都有意义,并且希望有人能够在这件事上为我提供帮助。如果您需要进一步的说明,请不要犹豫。非常感谢您的协助。

1 个答案:

答案 0 :(得分:-4)

检查您的用户名,它的拼写可能不正确

有关错误的信息,请检查此amazing description