因此,我正在编写一个案例函数,当事件(7-参与)发生时,会弹出一个交互式文本框,要求用户确认此操作。如果他们选择“确定”,则数据将移动到另一个电子表格。
这一切都很花哨,但可能需要修改才能整理。
无论如何,当用户选择“取消”时,就会出现此问题。 删除数据行而不只是离开函数。
我相信这个问题是最后两行删除了7位用户参与的所有内容,但是我还没有编写一段代码来将用户取消时的值降低到6位。
有人可以给我一些提示吗?
Private Sub Workbook_SheetChange(ByVal Sh作为对象,ByVal源作为范围) '可能在代码运行时禁用事件(并在退出前重新启用) '以防止递归。
' The three range rows are to move sepearate sections of data from pipeline into isolated blocks in tank.
If Source.Column <> 9 Then Exit Sub ' 9 = I
If Source.Cells.Count > 1 Then Exit Sub ' Check this first before making comparison on next line
If Source.Value <> "7 - engaged" Then Exit Sub
If MsgBox("Client status selected as engaged. Confirm to post to tank.", vbOKCancel) = vbOK Then
With ThisWorkbook.Worksheets("Tank") 'Produces an interactive dialoge box prompting the user to confirm they wish ti import to tank
'The code only fires if they confirm - if not, the line will remain in Pipeline.
Dim rowToPasteTo As Long
rowToPasteTo = .Cells(.Rows.Count, "B").End(xlUp).Row + 1
.Range("A" & rowToPasteTo & ":" & "D" & rowToPasteTo).Value = Sh.Range("A" & Source.Row & ":" & "M" & Source.Row).Value
.Range("G" & rowToPasteTo & ":" & "H" & rowToPasteTo).Value = Sh.Range("E" & Source.Row & ":" & "F" & Source.Row).Value
.Range("S" & rowToPasteTo & ":" & "U" & rowToPasteTo).Value = Sh.Range("K" & Source.Row & ":" & "M" & Source.Row).Value
End With
End If
If Source.Column = 9 And Source.Value = "7 - engaged" Then
Source.EntireRow.Delete
' The above line deleted the row from pipeline once it has been imported in Tank
End If
End Sub
答案 0 :(得分:0)
我现在添加了这段代码来解决问题。
If MsgBox("Client status selected as engaged. Confirm to post to tank.", vbOKCancel) = vbCancel Then
Source.Value = "6 - KYC in progress" ' If cancel is selected the value goes back to Case 6 and the line is kept.
End If