|
用循环应该是最慢的,用specialcell是最快的方法之一,当然,需要加一辅助列,进行判断,代码如下:
当30000再往上加的时候,超过34200的时候,就出错,所有的单元格都被染色,为什么呢?请高手指点
所有测试在2007+XP下进行
- Sub test()
- t1 = Timer
- With ActiveSheet.Cells(1, 1)
- .CurrentRegion.Clear
- .Resize(30000, 1).Value = "=randbetween(0,100)"
- .CurrentRegion.Value = .CurrentRegion.Value
- With .Offset(0, 1).Resize(30000, 1)
- .Value = "=if(a1<60,1,""me"")"
- .Value = .Value
- .SpecialCells(xlCellTypeConstants, xlNumbers).Offset(0, -1).Interior.ColorIndex = 50
- End With
- End With
- ActiveSheet.Columns("B:B").Delete
- t2 = Timer
- MsgBox t2 - t1 & "seconds"
- End Sub
复制代码 |
|