Как использовать кнопки поиска и обновления на заблокированном рабочем листе - PullRequest
0 голосов
/ 22 апреля 2019

Я ввел код для добавления данных на заблокированную рабочую таблицу, но команды поиска и обновления не работают при попытке изменить данные с помощью пользовательской формы.

Мне удалось найти способ добавления данных, но неткак заставить его работать для поиска и обновления

Private Sub Workbook_Open()
Sheet1.Protect Password:="xyz", UserInterfaceOnly:=True
End Sub

Private Sub cmdAdd_Click()
'to check the last filled row
lastrow = ThisWorkbook.Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
ThisWorkbook.Worksheets("Sheet1").Cells(lastrow + 1, 1).Value = txtInvoiceNumber.Text


Private Sub cmdFind_Click()
Dim totalrow As Long
totalrow = Sheet1.Range("A1").CurrentRegion.Rows.Count
For currentrow = 2 To totalrow
If Trim(txtLineNumber) = Trim(Cells(currentrow, 2)) Then
txtInvoiceNumber.Text = Cells(currentrow, 1)
txtInvoiceDate.Text = Cells(currentrow, 3)


Private Sub cmdUpdate_Click()
Dim totalrow As Long
totalrow = Sheet1.Range("A1").CurrentRegion.Rows.Count
For currentrow = 2 To totalrow
If Trim(txtLineNumber) = Trim(Cells(currentrow, 2)) Then
Cells(currentrow, 1) = txtInvoiceNumber.Text
Cells(currentrow, 3) = txtInvoiceDate.Text

Я хотел бы знать код, чтобы кнопки поиска / поиска и обновления также обновляли данные, пока рабочая таблица заблокирована.Спасибо

Ошибка enter image description here

Отладка enter image description here

Полный код

Private Sub cmdFind_Click()
Dim totalrow As Long
totalrow = Sheet1.Range("A1").CurrentRegion.Rows.Count
For currentrow = 2 To totalrow
If Trim(txtLineNumber) = Trim(Cells(currentrow, 2)) Then
txtInvoiceNumber.Text = Cells(currentrow, 1)
txtInvoiceDate.Text = Cells(currentrow, 3)
cmbCustomerName.Text = Cells(currentrow, 4)
txtDestinationC.Text = Cells(currentrow, 5)
txtDestinationCnty.Text = Cells(currentrow, 6)
txtLine.Text = Cells(currentrow, 7)
cmbBrand.Text = Cells(currentrow, 8)
cmbType.Text = Cells(currentrow, 9)
cmbProduct.Text = Cells(currentrow, 10)
cmbPackaging.Text = Cells(currentrow, 11)
txtCartons.Text = Cells(currentrow, 12)
txtQuantity.Text = Cells(currentrow, 13)
cmbCurrency.Text = Cells(currentrow, 14)
txtUnitPrice.Text = Cells(currentrow, 15)
txtDocumentation.Text = Cells(currentrow, 16)
txtAdditionalF.Text = Cells(currentrow, 17)
txtTransport.Text = Cells(currentrow, 18)
cmbStatus.Text = Cells(currentrow, 19)
txtPdDate.Text = Cells(currentrow, 20)
txtCustomerRef.Text = Cells(currentrow, 21)
txtLoadDate.Text = Cells(currentrow, 22)
txtASMnumber.Text = Cells(currentrow, 23)
cmbWHS.Text = Cells(currentrow, 24)
txtCompleteDate.Text = Cells(currentrow, 25)
txtAccPacNumber.Text = Cells(currentrow, 26)
cmbZeroInvReason.Text = Cells(currentrow, 27)
cmbRep.Text = Cells(currentrow, 28)
txtDriver.Text = Cells(currentrow, 29)
txtContactD.Text = Cells(currentrow, 30)
txtContainer.Text = Cells(currentrow, 31)
txtTruckNo.Text = Cells(currentrow, 32)
txtTrailerNo.Text = Cells(currentrow, 33)
txtTransporter.Text = Cells(currentrow, 34)
cmbTransportMode.Text = Cells(currentrow, 35)
txtPOnumber.Text = Cells(currentrow, 36)
cmbCancelR.Text = Cells(currentrow, 37)
txtCrRef.Text = Cells(currentrow, 38)
End If
Next currentrow
End Sub
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...