У меня есть рабочий лист, который, когда агент заполняет форму и нажимает «Отправить», разблокирует лист, добавляет строку данных и затем блокирует лист.
Проблема в том, что мне нужно добавить возможность разблокировать параметры «сортировка» и «автофильтр», пока они все еще защищены.
Я использую Microsoft Excel 365.
Я попытался вручную разблокировать параметры, а также добавить оператор Dim, но ничего не работает.Я продолжаю получать ошибку "несоответствие типов"
Private Sub cmdUpdate_Click()
Application.Calculation = xlCalculationManual
Sheets("Appointment Log").Select
ActiveSheet.Unprotect Password:="asdf"
Dim lastrow
Dim currentrow As Long
Dim LookUpID As Double
Dim RecordNumber As Double
RecordNumber = 0
'Data Validations:
If Me.cmbCategory.Value = "" Then
MsgBox "Please enter Category"
Me.cmbCategory.SetFocus
Exit Sub
End If
If Me.txtLookUpID.Value = "" Then
MsgBox "Please enter ID"
Me.txtLookUpID.SetFocus
Exit Sub
End If
LookUpID = txtLookUpID.Text
LookUpCategory = cmbCategory.Text
lastrow = 2 + Range("A2").Value
' searching for record number and assigning it to RecordNumber variable
For currentrow = 3 To lastrow
If Cells(currentrow, 5).Text = LookUpID And Cells(currentrow, 2).Text = LookUpCategory Then
If Cells(currentrow, 1).Value > RecordNumber Then
RecordNumber = Cells(currentrow, 1).Text
End If
End If
Next currentrow
If RecordNumber = 0 Then
MsgBox ("Cannot find ID")
End If
'Searching for record and updating it
For currentrow = 3 To lastrow
If Cells(currentrow, 1).Text = RecordNumber Then
Cells(currentrow, 12).Value = Me.cmbFollowUpResult
Cells(currentrow, 13).Value = Date
Cells(currentrow, 14).Value = Date
End If
Next currentrow
For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
ctl.Value = ""
End If
Next ctl
If RecordNumber > 0 Then
Answer = MsgBox("Your Entry was made, Would You like to make another Update Follow Up Result Entry?", vbQuestion + vbYesNo)
If Answer = vbYes Then
cmdUpdate_Click
End If
End If
Sheets("Appointment Log").Select
Application.Calculation = xlCalculationAutomatic
ActiveSheet.Protect Password:="asdf"