Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2324|回复: 1

[已解决]请教变量问题。

[复制链接]
发表于 2013-12-7 00:12 | 显示全部楼层 |阅读模式
Private Sub 库存需求分析2()
Dim Lastrow As Integer, i As Integer, x As Integer, Data()
Application.ScreenUpdating = False
Rows.Interior.ColorIndex = xlColorIndexNone
Lastrow = Cells(Rows.Count, 2).End(xlUp).Row
Data = Range("a2:f" & Lastrow)
x = 1
For i = 2 To UBound(Data)
   Cells(i + 1, 6) = Data(i, 5) - Data(i, 4)
   If Data(i, 4) > Data(i, 5) Then Range(Cells(i + 1, 1), Cells(i + 1, 6)).Interior.ColorIndex = 36
Next
Application.ScreenUpdating = True
End Sub

程序虽用到数组加快了速度,但红字部分还是分多次用到改变单元格对象的操作,就影响了速度。我想把所有需要改变颜色的单元格先装进变量,以求一次性地改,希望多节省时间。


商品库存需求分析表(chb).rar (10.16 KB, 下载次数: 0)
发表于 2013-12-7 00:30 | 显示全部楼层    本楼为最佳答案   
用union把要操作的对象组合后,循环结束后再来一次设置颜色。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-25 16:20 , Processed in 0.518926 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表