Excelmacroscheckbox

我有这张桌子

表

如果可能的话使用macros,我想:

  1. 当检查具有30%的值的框时,它将复制到“总计select的”30%

  2. 用户只能选中一个框

  3. 我只想当用户选中方框来评估point1时,他会select其中一个评级(0%-30%-60%-100%),而他select的任何内容都将复制到总权值中。

我不知道如何为每个框定义一个值?

这个代码应该在很大程度上做你想要的工作。 将其安装在您希望执行操作的工作表的代码表中。 请注意,该表上不需要checkbox。 代码正在创build它们。 但是你确实需要格式化表格上的单元格以显示数字(而不是checkbox)。

Private Sub Worksheet_SelectionChange(ByVal Target As Range) ' 01 Oct 2017 Dim Rng As Range On Error GoTo ErrExit If Target.Cells.Count > 1 Then Exit Sub ' Specify the range where you want checkboxes to appear when clicked:- ' the range is defined as starting from C2 end ending ' at the cell in column F in the last used row in column A ' if column A has a fixed number of entries, like "Point 1 to Point 5" ' "Cells(Rows.Count, "A").End(xlUp).Row" may be replaced by a fixed row number Set Rng = Range(Cells(2, "C"), _ Cells(Cells(Rows.Count, "A").End(xlUp).Row, "F")) On Error GoTo 0 If Not Application.Intersect(Target, Rng) Is Nothing Then With Target Set Rng = Range(Cells(.Row, Rng.Column), _ Cells(.Row, Rng.Column + Rng.Columns.Count)) Rng.ClearContents ' Column "B" is "Total selected" ' it is assigned the value from row 1 Cells(.Row, "B").Value = Cells(1, .Column).Value .Font.Name = "Wingdings" .Font.Size = 14 ' set the font size as required .HorizontalAlignment = xlCenter .Value = ChrW(254) End With End If Exit Sub ErrExit: ' the likely reason is that column A is blank. ' Make sure that there is an entry in column A ' for every row in which you may want to set a checkbox MsgBox Err & vbCr & Err.Description, _ vbCritical, "Malfunction" End Sub 

我不明白你想要在“总重量”栏中有什么。 您可以使用工作表function填写该列。