gpt4 book ai didi

vba - 不断收到运行时错误 '13' : Type mismatch when a section of the sheet is deleted

转载 作者:行者123 更新时间:2023-12-03 03:21:53 26 4
gpt4 key购买 nike

我的代码的目的非常简单。它旨在当用户提交表单时隐藏和取消隐藏某些单元格。当用户希望重新开始并一次清除多个单元格中的数据时,他们会遇到运行时错误“13”类型不匹配。下面是代码,有人可以帮忙吗?

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 And Target.Row = 2 And Target.Value = "A" Then
Application.Columns("F:G").Select
Application.Selection.EntireColumn.Hidden = True

End If
If Target.Column = 2 And Target.Row = 2 And Target.Value = "B" Then
Application.Columns("F:P").Select
Application.Selection.EntireColumn.Hidden = True

End If
If Target.Column = 2 And Target.Row = 2 And Target.Value = "C" Then
Application.Columns("F:P").Select
Application.Selection.EntireColumn.Hidden = True

End If
If Target.Column = 2 And Target.Row = 2 And Target.Value = "D" Then

Application.Columns("F:P").Select
Application.Selection.EntireColumn.Hidden = False
End If
If Target.Column = 2 And Target.Row = 2 And Target.Value = "E" Then

Application.Columns("F:P").Select
Application.Selection.EntireColumn.Hidden = False

End If

最佳答案

尝试将 B2 与可能的多细胞目标隔离。

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Cells(2, "B")) Is Nothing Then
Columns("F:P").EntireColumn.Hidden = False
Select Case Cells(2, "B").Value2
Case "Exceptions Reviewer"
Columns("F:G").EntireColumn.Hidden = True
Case "CAT Payouts Tracker Entry", _
"CAT Payouts Tracker Supervisor", _
"Agent Error Review", _
"Agent Error and Exceptions Reviewer"
Columns("F:P").EntireColumn.Hidden = True
Case Else
'do nothing
End Select
End If
End Sub

关于vba - 不断收到运行时错误 '13' : Type mismatch when a section of the sheet is deleted,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49825989/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com