Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba Excel因工作表选择更改而不断崩溃_Vba_Excel - Fatal编程技术网

Vba Excel因工作表选择更改而不断崩溃

Vba Excel因工作表选择更改而不断崩溃,vba,excel,Vba,Excel,我正在运行两个VBA公式 第一列隐藏第一列中包含空信息的所有单元格 Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim c As Range On Error Resume Next Application.ScreenUpdating = False For Each c In Range("A3:A49") If c.Value = vbNullStri

我正在运行两个VBA公式

第一列隐藏第一列中包含空信息的所有单元格

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

     Dim c As Range
     On Error Resume Next

     Application.ScreenUpdating = False

     For Each c In Range("A3:A49")
        If c.Value = vbNullString Then
            c.EntireRow.Hidden = True
        End If
    Next c

    For Each c In Range("A3:A47")
        If c.Value <> vbNullString Then
            c.EntireRow.Hidden = False
        End If
    Next c

    Application.ScreenUpdating = True

End Sub
Private子工作表\u selection更改(ByVal目标作为范围)
调光范围
出错时继续下一步
Application.ScreenUpdating=False
对于范围内的每个c(“A3:A49”)
如果c.Value=vbNullString,则
c、 EntireRow.Hidden=True
如果结束
下一个c
对于范围内的每个c(“A3:A47”)
如果c.值为vbNullString,则
c、 EntireRow.Hidden=False
如果结束
下一个c
Application.ScreenUpdating=True
端接头
第二个公式将数据串在一起,并在单击按钮时将此信息放置在下一个空单元格(即第一个隐藏单元格)中

Option Explicit

    Dim iwsh As Worksheet
    Dim owsh As Worksheet
    Dim output As String
    Dim i As Integer

    Sub Copy()

    Set iwsh = Worksheets("Budget")
    Set owsh = Worksheets("Release Burnup")

    i = 3

    While owsh.Cells(i, 1) <> ""

    i = i + 1

    Wend

    output = "R" & iwsh.Cells(13, 2).Value & "-S" & iwsh.Cells(14, 2).Value

    owsh.Cells(i, 1) = output

    ActiveSheet.EnableCalculation = False
    ActiveSheet.EnableCalculation = True

End Sub
选项显式
Dim iwsh As工作表
Dim owsh As工作表
将输出设置为字符串
作为整数的Dim i
子副本()
设置iwsh=工作表(“预算”)
设置owsh=工作表(“释放燃耗”)
i=3
而owsh.Cells(i,1)”
i=i+1
温德
output=“R”和iwsh.Cells(13,2).Value&“-S”和iwsh.Cells(14,2).Value
owsh.单元格(i,1)=输出
ActiveSheet.EnableCalculation=False
ActiveSheet.EnableCalculation=True
端接头
以前,这并没有造成任何问题。。。每当我试图用新数据从其中一个单元格中删除信息时,发生了一些导致工作簿崩溃的情况

PS:这是我的其他配方的列表。也许这些代码中有什么东西与前面提到的代码交互

Private Sub NewMemberBut_Click()

    'causes userform to appear
    NewMember.Show

    'reformats button because button kept changing size and font
    NewMemberBut.AutoSize = False
    NewMemberBut.AutoSize = True
    NewMemberBut.Height = 40.25
    NewMemberBut.Left = 303.75
    NewMemberBut.Width = 150

End Sub

'Similar code to the problematic code in question, but this one works fine
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Dim c As Range
    On Error Resume Next

    Application.ScreenUpdating = False

    For Each c In Range("A3:A35,A41:A80")
        If c.Value = vbNullString Then
            c.EntireRow.Hidden = True
        End If
    Next c

    For Each c In Range("A3:A35,A41:A80")
        If c.Value <> vbNullString Then
            c.EntireRow.Hidden = False
        End If
    Next c

    Application.ScreenUpdating = True

End Sub


'Code for UserForm

Option Explicit

    Dim mName As String
    Dim cName As String
    Dim mRole As String
    Dim cRole As String
    Dim i As Integer
    Dim x As Integer
    Dim Perc As Integer
    Dim Vac As Integer
    Dim Prj As Worksheet
    Dim Bud As Worksheet

Private Sub NewMember_Initialize()

    txtName.Value = ""

    cboRoleList.Clear

    Scrum.Value = False

    txtPercent.Value = ""

    txtVacation.Value = ""

    txtName.SetFocus

End Sub

Private Sub AddMember_Click()

    If Me.txtName.Value = "" Then
        MsgBox "Please enter a Member name.", vbExclamation, "New Member"
        Me.txtName.SetFocus
    Exit Sub
    End If

    If Me.cboRoleList = "Other" And Me.txtCustomRole = "" Then
        MsgBox "Please provide a role name.", vbExclamation, "Other Role"
    Exit Sub
    End If

    If Me.cboRoleList.Value = "" Then
        MsgBox "Please select a Role.", vbExclamation, "Member Role"
        Me.cboRoleList.SetFocus
    Exit Sub
    End If

    If Me.cboRoleList <> "Other" And Me.txtPercent = "" Then
        MsgBox "Please select a valid percentage to be applied to this sprint.", vbExclamation, "Sprint Percent"
        Me.txtPercent.SetFocus
    Exit Sub
    End If

    If Me.txtPercent.Value > 100 And Me.txtPercent <> "" Then
        MsgBox "Please select a valid percentage to be applied to this sprint.", vbExclamation, "Sprint Percent"
        Me.txtPercent.SetFocus
    Exit Sub
    End If

    If Me.txtVacation.Value = "" Then
        Me.txtVacation.Value = 0
    End If

    Dim i As Long

    Set Prj = Worksheets("Project Team")
    Set Bud = Worksheets("Budget")

    Prj.Activate

    i = 5
    x = 1
    If Me.cboRoleList.Value = "Other" Then
        i = 46
    End If


    While Prj.Cells(i, 1) <> ""
        i = i + 1
    Wend

    If cboRoleList = "Other" Then
        Cells(i, x).Value = txtCustomRole.Value
    End If

    If cboRoleList <> "Other" Then
        Cells(i, x).Value = cboRoleList.Value
    End If
    x = x + 1

    Cells(i, x).Value = txtName.Value
    x = x + 1

    If Me.cboRoleList.Value <> "Other" Then
        Cells(i, x).Value = txtPercent.Value
    End If

    Unload Me
End Sub


Private Sub CloseBut_Click()

    Unload Me

End Sub
Private Sub newmembers但单击()
'导致出现userform
新成员,秀
'重新格式化按钮,因为按钮不断更改大小和字体
NewMemberBut.AutoSize=False
NewMemberBut.AutoSize=True
NewMemberBut.Height=40.25
NewMemberBut.Left=303.75
NewMemberBut.Width=150
端接头
'类似于有问题的代码,但这一个工作良好
专用子工作表\u选择更改(ByVal目标作为范围)
调光范围
出错时继续下一步
Application.ScreenUpdating=False
对于范围内的每个c(“A3:A35,A41:A80”)
如果c.Value=vbNullString,则
c、 EntireRow.Hidden=True
如果结束
下一个c
对于范围内的每个c(“A3:A35,A41:A80”)
如果c.值为vbNullString,则
c、 EntireRow.Hidden=False
如果结束
下一个c
Application.ScreenUpdating=True
端接头
'用户表单的代码
选项显式
Dim mName作为字符串
将cName设置为字符串
作为字符串的Dim mRole
像弦一样的低沉的声音
作为整数的Dim i
作为整数的Dim x
Dim Perc作为整数
作为整数的Dim Vac
Dim Prj As工作表
用暗淡的花蕾做工作表
私有子NewMember_Initialize()
txtName.Value=“”
CBOROLELLIST,清除
Scrum.Value=False
txtPercent.Value=“”
txtVacation.Value=“”
txtName.SetFocus
端接头
私有子添加成员\u单击()
如果Me.txtName.Value=”“,则
MsgBox“请输入成员名称”,VBE感叹号,“新成员”
Me.txtName.SetFocus
出口接头
如果结束
如果Me.cboRoleList=“其他”和Me.txtCustomRole=”“,则
MsgBox“请提供角色名称”,VBE感叹号,“其他角色”
出口接头
如果结束
如果Me.cboRoleList.Value=”“,则
MsgBox“请选择一个角色”,VBE感叹号,“成员角色”
Me.cboRoleList.SetFocus
出口接头
如果结束
如果Me.cboRoleList“Other”和Me.txtPercent=”“,则
MsgBox“请选择要应用于此冲刺的有效百分比”。vb感叹号,“冲刺百分比”
Me.txt.SetFocus
出口接头
如果结束
如果Me.txtPercent.Value>100且Me.txtPercent为“”,则
MsgBox“请选择要应用于此冲刺的有效百分比”。vb感叹号,“冲刺百分比”
Me.txt.SetFocus
出口接头
如果结束
如果Me.txtVacation.Value=”“,则
Me.txtVacation.Value=0
如果结束
我想我会坚持多久
设置Prj=工作表(“项目团队”)
Set Bud=工作表(“预算”)
Prj.激活
i=5
x=1
如果Me.cboRoleList.Value=“其他”,则
i=46
如果结束
而Prj.Cells(i,1)”
i=i+1
温德
如果cboRoleList=“其他”,则
单元格(i,x).Value=txtCustomRole.Value
如果结束
如果CBOROLLELIST“其他”,则
单元格(i,x).Value=cboRoleList.Value
如果结束
x=x+1
单元格(i,x).Value=txtName.Value
x=x+1
如果Me.cboRoleList.Value为“其他”,则
单元格(i,x).Value=txtPercent.Value
如果结束
卸下我
端接头
私有子系统关闭,但单击()
卸下我
端接头

将事件驱动的工作表\u选择更改为工作表\u更改并进一步隔离,仅在A3:A49中发生更改时进行处理

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Intersect(Target, Range("A3:A49")) Is Nothing Then
        On Error GoTo safe_exit
        Application.EnableEvents = False
        Application.ScreenUpdating = False
        Dim c As Range
        For Each c In Intersect(Target, Range("A3:A49"))
            c.EntireRow.Hidden = CBool(c.Value = vbNullString)
        Next c
    End If

safe_exit:
    Application.EnableEvents = True
    Application.ScreenUpdating = True

End Sub

警告:单元格公式中的单元格更改不会触发工作表更改。只能通过键入、删除或拖动单元格内容。添加或删除公式将触发它,但当公式的结果从工作簿中某个位置的另一个值更改时不会触发。这不应影响您,因为没有公式可以返回vbNullString,但其他公式值得一提。

将事件驱动的工作表_选择更改为工作表_更改,并仅在A3:A49中发生更改时进行处理以进一步隔离

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Intersect(Target, Range("A3:A49")) Is Nothing Then
        On Error GoTo safe_exit
        Application.EnableEvents = False
        Application.ScreenUpdating = False
        Dim c As Range
        For Each c In Intersect(Target, Range("A3:A49"))
            c.EntireRow.Hidden = CBool(c.Value = vbNullString)
        Next c
    End If

safe_exit:
    Application.EnableEvents = True
    Application.ScreenUpdating = True

End Sub

警告:单元格公式中的单元格更改不会触发工作表更改。只能通过键入、删除或拖动单元格内容。添加或删除公式将触发它,但当公式的结果从工作簿中某个位置的另一个值更改时不会触发。这不会影响您,因为任何公式都不能返回vbNullString,但其他公式值得一提。

答案是“what changed”,以前工作过,停止工作,那么什么改变了?隔离该更改,您应该能够解决此问题。
c.EntireRow.Hidden=cbool(