Excel精英培训网

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

小小的漏洞

[复制链接]
发表于 2015-10-11 13:33 | 显示全部楼层 |阅读模式
本帖最后由 jbljypx 于 2015-10-11 17:07 编辑

  1. '《VBA数组-5:数组与单元格格式》有些小小的漏洞:
  2. '如D80>500,没有着色,等等;
  3. '如最后一行D10000>500时,不会着色。
  4. '下面修补程序避免了上述漏洞。
  5. '欢迎批评指正。

  6. Sub 数组方法()
  7. Dim arr, t, i
  8. Dim x As Integer
  9. Dim sr As String, sr1 As String
  10. 清除颜色
  11. t = Timer
  12. arr = Range("d2:d" & Range("a65536").End(xlUp).Row)
  13. For x = 1 To UBound(arr)
  14. If x = UBound(arr) And sr <> "" Then Range(Left(sr, Len(sr) - 1)).Interior.ColorIndex = 3
  15. If x = UBound(arr) And arr(x, 1) > 500 Then 'jbl新增语句
  16. Range("A" & x + 1 & ":D" & x + 1).Interior.ColorIndex = 3: MsgBox Timer - t: Exit Sub 'jbl新增语句
  17. End If
  18. If x = UBound(arr) And arr(x, 1) <= 500 Then 'jbl新增语句
  19. MsgBox Timer - t: Exit Sub 'jbl新增语句
  20. End If
  21. If arr(x, 1) > 500 Then
  22. sr1 = sr
  23. sr = sr & "A" & x + 1 & ":D" & x + 1 & ","
  24. i = Len(sr) 'jbl增加的观察语句
  25. If Len(sr) > 255 Then
  26. sr = sr1
  27. x = x - 1
  28. Range(Left(sr, Len(sr) - 1)).Interior.ColorIndex = 3
  29. sr = ""
  30. i = "" 'jbl增加的观察语句
  31. End If
  32. End If
  33. 'If x = 9998 Then Stop 'jbl增加的终止语句,以观察程序的结尾运行情况
  34. Next x
  35. MsgBox Timer - t
  36. End Sub
复制代码
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-20 14:30 , Processed in 0.277859 second(s), 12 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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