0

I would like to move the contents of excel cells when a checkbox is clicked, to another worksheet, I would also like to clear the contents from the original, I have searched on google and cannot find a solution, I may not be understanding how to do it, please advise the best way to write some code

thank you

4

1 回答 1

0

在 Excel 2010 和更新版本中,您可以通过转到文件 -> 选项来打开开发人员菜单,然后单击左侧栏中的“自定义功能区”。在最右边的列中选中“开发人员”框并点击“确定”。

在开发人员选项卡下,现在在顶部栏上可见,选择“Visual basic”。

右键单击左栏中的“Microsoft Excel 对象”行,然后“插入”->“模块”

现在在右侧的主窗口(空)中复制以下代码。

Sub MoveData()
  if ThisWorkbook.Worksheets(1).Shapes("Check Box 1").OLEFormat.Object.Value = 1 then
     Range("A1:A5").Select
     Selection.Cut
     Sheets("Sheet2").Select
     Range("A1").Select
     ActiveSheet.Paste
     Range("A1").Select
  End If
End Sub

现在回到您的 Excel 工作表(假设 sheet1),在开发人员选项卡下单击“插入”并选中复选框。现在在您希望复选框所在的工作表上拖动一个矩形。

右键单击复选框并“分配宏”。选择“移动数据”并点击“确定”。

现在将数据输入到单元格 A1 到 A5 的 sheet1 中,然后选中该框。它将从 sheet1 中删除并将其粘贴到 sheet2 中。

当您取消选中该框时,什么都不会发生。

如果要更改复选框的名称,可以右键单击它并选择“格式控制”并更改“替代文本”。确保更改宏代码以匹配它。

于 2013-09-11T22:27:43.650 回答