|
发表于 2016-6-7 22:51
|
显示全部楼层
本楼为最佳答案
excelpxfans001 发表于 2016-6-7 22:42
从左至右的第一个填充红色的单元格。 - Sub xx()
- Dim rng As Range, i&, dc As Object, c As Integer, x As Integer, y As Integer
- On Error Resume Next
- Set rng = Selection
- If Application.Count(rng) < 10 Then Exit Sub '至少选择10个,需要与参数匹配
- If rng.Rows.Count > 1 Then Exit Sub
- c = rng.Columns.Count
- Set dc = CreateObject("scripting.dictionary")
- rng.Interior.ColorIndex = 0
- y = 2000
- With dc
- Do
- Randomize
- x = Int(Rnd * c + 1)
- If Not dc.Exists(x) Then
- .Add x, ""
- rng(1, x).Interior.Color = 192
- If x < y Then y = x
- End If
- Loop Until .Count = 10 '在此修改参数
- End With
- rng(1, y).Select
- End Sub
复制代码 |
|