我现有的代码使用ActiveX复选框修改工作簿中基于单元格" I16"的工作表的标题和可见性。我想要做的是设置一个将要修改的更改事件,如果用户更改了Cell" I16"的内容,则允许进一步修改工作表。 (这是工作表的标题)。
该代码旨在执行以下操作:
问题?代码确实......没有。我改变了目标地址,没有任何反应。我调整代码,调整范围等,无处可去。
提前为您即将见证的业余编码道歉,并感谢您对此的帮助。
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim ws As Worksheet
Dim sheetName As String
If Target.Address = "I16" Then
If WorksheetExists(sheetName) Then
Exit Sub
Else
MsgBox "Are you sure you want to change" & vbNewLine & "the name of this Allowance?", vbYesNo + vbQuestion, "Confirm Name Change"
If Yes Then
Set ws = Sheet34
ws.Name = sheetName
MsgBox "Would you like to clear the data from" & vbNewLine & "this Allowance?", vbYesNo + vbQuestion, "Confirm Data Clear"
If Yes Then
LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
Worksheets.Sheet34.Rows.Range("C9:LastRow, -1", D9:LastRow, -1, E9:LastRow, -1, F9:LastRow, -1, H9:LastRow, -1, J9:LastRow, -1, L9:LastRow, -1, N9:LastRow, -1, P9:LastRow, -1).Clear
Else
Exit Sub
End If
Else
Application.EnableEvents = False
Application.Undo
Exit Sub
Application.EnableEvents = True
End If
End If
End If
End Sub
答案 0 :(得分:2)
您不会捕获MsgBox
的返回值。
Dim result As VbMsgBoxResult
result = MsgBox("Are you sure?", vbOKCancel)
If result = vbOK Then
...
Else
...
End if