程序excel返回一个特定的值

我有一个电子表格将用于调查。

如何让单元格只返回“x”,而不pipe调查接受者input什么内容。

例如,如果我在单元格中写入“w”,它应该变成“x”。

当我保护工作簿或工作表时,我认为有一个select。 因为我可以从另一个电子表格(具有此function)告诉它只有在工作簿受到保护的情况下才起作用。

我试图谷歌,但似乎我不知道正确的关键字find答案。

另外,我find了一套Vba代码,但我不确定这是否正确。 我不想附上代码,因为我不想在这里混淆任何回应。

感谢您提供的任何帮助。

将这段代码放在工作表模块中,并在testing列A(1)中的单元格时激活,

工作表模块在哪里?

在这里输入图像说明

复制并粘贴代码,

Private Sub Worksheet_Change(ByVal Target As Range) If Target.Count > 1 Then Exit Sub If Intersect(Target, Range("A1,B1,C1,A4,B4,C4")) Is Nothing Then Exit Sub Application.EnableEvents = 0 If Target <> "" Then Target = "X" Application.EnableEvents = 1 End Sub 

这应该为你工作(只需将范围更改为您需要的范围):

 Option Explicit Sub worksheet_Change(ByVal Target As Range) On Error GoTo errorbutler 'error handler - important to have this in case your macro does a booboo Application.Calculation = xlCalculationManual 'turn off automatic calculation to speed up the macro Application.EnableEvents = False 'turn off events in order to prevent an endless loop Dim LR, cell As Range 'Declare your variables Set LR = Range("A1:b3") ' Select range of cells this macro would apply to For Each cell In Target 'Loops through the cells that user have changed If Union(cell, LR).Address = LR.Address Then 'Checks if the changed cell is part of your range cell.Value="x" 'changes the value of that cell to x End if Next cell Errorexit: 'part of error handling procedure Application.EnableEvents = True 'Turn autocalc back on Application.Calculation = xlCalculationAutomatic 'turn events back on Exit Sub Errorbutler: 'error handling procedure Debug.Print Err.Number & vbNewLine & Err.Description Resume Errorexit End Sub 

哦,是的,这个代码应该放在工作表模块中 – 就像Dave向你展示的一样