当我卸载UserForm时,它会打开一个不需要的工作表。我怎么让它停下来?

时间:2016-06-03 16:01:13

标签: excel vba

每当我卸载此UserForm时,它都会打开" DataEntry"有时会使显示器无响应。

我有多个UserForms,没有其他人有同样的问题。

UserForm的代码:

Sub btnCalc_Click()
  Dim LastRow As Long, ws As Worksheet
    Set ws = Sheets("DataEntry")
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1 'Finds the last blank row
ws.Range("A" & LastRow).Value = TextBox1.Text 'Adds the TextBox1 into Col A & Last Blank Row
LastRow = ws.Range("B" & Rows.Count).End(xlUp).Row + 1
ws.Range("B" & LastRow).Value = TextBox13.Text
LastRow = ws.Range("C" & Rows.Count).End(xlUp).Row + 1
ws.Range("C" & LastRow).Value = TextBox12.Text
LastRow = ws.Range("D" & Rows.Count).End(xlUp).Row + 1
ws.Range("D" & LastRow).Value = TextBox11.Text
LastRow = ws.Range("E" & Rows.Count).End(xlUp).Row + 1
ws.Range("E" & LastRow).Value = TextBox10.Text
LastRow = ws.Range("F" & Rows.Count).End(xlUp).Row + 1
ws.Range("F" & LastRow).Value = TextBox7.Text
LastRow = ws.Range("G" & Rows.Count).End(xlUp).Row + 1
ws.Range("G" & LastRow).Value = TextBox8.Text
LastRow = ws.Range("H" & Rows.Count).End(xlUp).Row + 1
ws.Range("H" & LastRow).Value = TextBox9.Text
LastRow = ws.Range("I" & Rows.Count).End(xlUp).Row + 1
ws.Range("I" & LastRow).Value = ComboBox1.Text

ws.Range("O1").Value = TextBox1.Text

Worksheets("ResultSplash").Activate
Range("A1").Select
Application.ScreenUpdating = True

Application.Wait (Now + TimeValue("0:00:02"))


End Sub

Sub ResultSplash()
Worksheets("ResultSplash").Activate
End Sub
Private Sub Label22_Click()
 Unload Me
 End Sub

Private Sub UserForm_Initialize()
 Dim cPart As Range
Dim cLoc As Range
Dim ws As Worksheet
Set ws = Worksheets("LookupLists")

For Each cPart In ws.Range("Industries")
  With Me.ComboBox1
    .AddItem cPart.Value
    .List(.ListCount - 1, 1) = cPart.Offset(0, 1).Value
  End With
Next cPart


Call RemoveTitleBar(Me)
End Sub

Private Sub ComboBox1_Change()
Select Case ComboBox1.Value
Case "Apparel/Footwear"
    Label13.Caption = "4,000"
    Label15.Caption = "__"
    Label16.Caption = "82%"
    Label17.Caption = "1.5%"
    Label18.Caption = "18%"
    Label19.Caption = "__"
    Label20.Caption = "$95"
Case "Beauty/Skincare"
    Label13.Caption = "1,300"
    Label15.Caption = "__"
    Label16.Caption = "78%"
    Label17.Caption = "-0.3%"
    Label18.Caption = "22%"
    Label19.Caption = "__"
    Label20.Caption = "$90"
Case "Niche/Specialty"
    Label13.Caption = "3,900"
    Label15.Caption = "__"
    Label16.Caption = "82%"
    Label17.Caption = "0%"
    Label18.Caption = "18%"
    Label19.Caption = "__"
    Label20.Caption = "$93"
Case "Food/Beverage"
    Label13.Caption = "2,900"
    Label15.Caption = "__"
    Label16.Caption = "79%"
    Label17.Caption = "1.6%"
    Label18.Caption = "21%"
    Label19.Caption = "__"
    Label20.Caption = "$94"
Case "Computers/Electronics"
    Label13.Caption = "1,500"
    Label15.Caption = "__"
    Label16.Caption = "84%"
    Label17.Caption = "1.2%"
    Label18.Caption = "16%"
    Label19.Caption = "__"
    Label20.Caption = "$903"
Case "Other"
    Label13.Caption = "4,800"
    Label15.Caption = "__"
    Label16.Caption = "78%"
    Label17.Caption = "1.5%"
    Label18.Caption = "22%"
    Label19.Caption = "__"
    Label20.Caption = "$94"
End Select

End Sub

Private Sub TextBox13_AfterUpdate()
If IsNumeric(TextBox13) Then
    TextBox13 = Format(TextBox13, "#,##0")
Else
    ErrorForm.Show
    TextBox13 = ""
End If
End Sub

Private Sub TextBox12_AfterUpdate()
If IsNumeric(TextBox12) Then
    TextBox12 = Format(TextBox12, "#,##0")
Else
    ErrorForm.Show
    TextBox12 = ""
End If
End Sub

Private Sub TextBox11_AfterUpdate()
If IsNumeric(TextBox11) Then
    TextBox11.Value = TextBox11.Value * 0.01
    TextBox11 = Format(TextBox11, "#%")
Else
    ErrorForm.Show
    TextBox11 = ""
End If
 End Sub

Private Sub TextBox10_AfterUpdate()
If IsNumeric(TextBox10) Then
    TextBox10.Value = TextBox10.Value * 0.01
    TextBox10 = Format(TextBox10, "#%")
Else
    ErrorForm.Show
    TextBox10 = ""
End If
End Sub

Private Sub TextBox7_AfterUpdate()
If IsNumeric(TextBox7) Then
    TextBox7.Value = TextBox7.Value * 0.01
    TextBox7 = Format(TextBox7, "#%")
Else
    ErrorForm.Show
    TextBox7 = ""
End If
End Sub

Private Sub TextBox8_AfterUpdate()
If IsNumeric(TextBox8) Then
    TextBox8.Value = TextBox8.Value * 0.01
    TextBox8 = Format(TextBox8, "#%")
Else
    ErrorForm.Show
    TextBox8 = ""
End If
End Sub

Private Sub TextBox9_AfterUpdate()
If IsNumeric(TextBox9) Then
    TextBox9 = Format(TextBox9, "$#")
Else
    ErrorForm.Show
    TextBox9 = ""
End If
End Sub

我试图将信息输入到" DataEntry"表格,并显示" ResultSplash"页面,但每当我关闭UserForm时,它会显示" DataEntry"片材。

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

您可以在卸载行后添加以下行:

ActiveWorokbook.Sheets(DataEntry).Visible = False

如果这是您正在寻找的