求救大神帮我做一个EXCEL的VBA:用鼠标选中一块区域,在这块区域中,随机清除其中10个单元格的数据,谢谢

如题所述

代码 如下:

需Excel 内启用宏 使用,Alt+F8运行

Sub randclear()
   Set dic = CreateObject("scripting.dictionary")
   num = Selection.Cells.Count
   If num < 10 Then
     MsgBox "选区单元格数小于10,请重新选择": Exit Sub
   End If
   Do
    Randomize
    n = Int(Rnd * num) + 1
    dic(n) = ""
  Loop Until dic.Count = 10
  dk = dic.keys
   For i = 0 To 9
     Selection.Cells(dk(i)).ClearContents
   Next
   MsgBox "随机清除完成"
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-08-23
可以的。。表格发来
相似回答