Приведенный ниже код проверит, изменилось ли содержимое E3, и если да, то проверит, содержит ли ячейка текст «Word» (без учета регистра), если он содержит текст, очистит ячейки G3,H3 & I3.
Поместите код под лист, с которым вы работаете, используя событие Worksheet_Change
:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$E$3" Then 'check if the value in cell E3 has changed
If InStr(UCase(Target), "WORD") > 0 Then
'check if the text "Word" (not case sensitive) is within the contents of the cell
Range("G3:I3").ClearContents 'if yes then clear G3:I3
MsgBox "Please fill the cells G3, H3 & I3", vbInformation, "Populate"
End If
End If
End Sub
ОБНОВЛЕНИЕ:
В дополнение к вашим комментариям, я теперь обновил свой ответ, приведенный ниже код заблокирует все ячейки на вашем рабочем листе, кроме столбца E, после заполнения ячейки в столбце E он разблокирует столбцы в этой строке для G,H и я, чтобы пользователь мог ввести необходимые данные:
Sub LockCells()
'lock all cells apart from Column E
Dim ws As Worksheet: Set ws = ThisWorkbook.Worksheets("Sheet1")
ws.Range("E:E").Locked = False 'leave unlocked
ws.Range("G:I").Locked = True 'lock these columns
ws.Protect Password:="xx", UserInterfaceOnly:=True
'change the password to whatever you wish
End Sub
Sub UnlockWorksheet()
'You might need this to unlock the sheet
Dim ws As Worksheet: Set ws = ThisWorkbook.Worksheets("Sheet1")
ws.Unprotect Password:="xx"
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet: Set ws = ThisWorkbook.Worksheets("Sheet1")
If Target.Column = 5 Then 'check if the value in Column E has changed
If Target.Value <> "" Then
ws.Range("G" & Target.Row & ":I" & Target.Row).Locked = False
'check if the text "Word" (not case sensitive) is within the contents of the cell
ws.Range("G" & Target.Row & ":I" & Target.Row).ClearContents 'if yes then clear G:I
MsgBox "Please fill the columns G, H & I", vbInformation, "Populate"
End If
End If
End Sub