У меня есть 2 пользовательские формы, в которых при нажатии на cmd2_click
из userform3
появляется всплывающее окно userform4
. При выгрузке userform4
код работает как положено. Однако userform3
выгружается сам по себе на end sub
из cmd2_click
Я не могу найти причину выгрузки userform3
. Ниже приведен код. Как было сказано ранее, cmd2_click
выполняется должным образом. Все значения копируются в соответствующие ячейки. Проблема только в конце кода.
Private Sub Cmd2_Click()
Dim rwcnt, i As Long
Set ws = Nothing: Set ws = Sheet4
UserForm4.Show
If Label14.Caption = 1 Then
here: With ws
rwcnt = .Range("A" & .Rows.Count).End(xlUp).Row: rwcnt = rwcnt + 1
.Cells(rwcnt, 1) = TextBox1.Text
.Cells(rwcnt, 11) = Det22.Text
.Cells(rwcnt, 12) = Format(Now(), "DD/MMM/YY")
For i = 2 To 10
If i = 4 Then i = 5
.Cells(rwcnt, i) = Me.Controls.Item("Det" & i).Text
Me.Controls.Item("Det" & i).Enabled = True
Next i: i = 0
End With
Set ws = Nothing
Det22.Enabled = True
If Label14.Caption = 3 Then GoTo here1
Clear
GoTo Ending
End If
If Label14.Caption = 2 Then
here1: Set ws = Sheet8
With ws
rwcnt = .Range("A" & .Rows.Count).End(xlUp).Row: rwcnt = rwcnt + 1
.Cells(rwcnt, 1) = TextBox1.Text
.Cells(rwcnt, 5) = Label19.Caption
.Cells(rwcnt, 11) = Det22.Text
.Cells(rwcnt, 12) = Format(Now(), "DD/MMM/YY")
For i = 11 To 18
If i = 14 Then i = 15
.Cells(rwcnt, i - 9) = Me.Controls.Item("Det" & i).Text
Me.Controls.Item("Det" & i).Enabled = True
Next i: i = 0
Frame4.Enabled = True
For i = 1 To 3
If Me.Controls.Item("Optionbutton" & i).Value = True Then
.Cells(rwcnt, 10) = Me.Controls.Item("Optionbutton" & i).Caption
.Cells(rwcnt, 9) = TextBox17.Text
Me.Controls.Item("Optionbutton" & i).Value = False
End If
Next i: i = 0
Frame5.Enabled = True
Det22.Enabled = True
End With
Set ws = Nothing
Clear
GoTo Ending
End If
If Label14.Caption = 3 Then
GoTo here
End If
Ending:
End Sub 'UF4 is unloading by itself here
Public Sub Clear()
If Det7.Text = "Yes" Then
For i = 13 To 22
If i = 14 Then i = 15
If i = 19 Then i = 22
Sheet6.Cells(Label12.Caption, i) = ""
Me.Controls.Item("Det" & i).Text = ""
Next i
Cmd2.Enabled = False: Cmd4.Enabled = True
Else
Sheet6.Cells(Label12.Caption, 22) = "": Det22.Text = ""
Cmd2.Enabled = False: Cmd4.Enabled = True
End If
End Sub