Excel精英培训网

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

[已解决]用vba表示相连数字

[复制链接]
发表于 2013-3-6 08:35 | 显示全部楼层 |阅读模式
0个黄.zip (26.9 KB, 下载次数: 9)
发表于 2013-3-6 08:55 | 显示全部楼层
本帖最后由 hwc2ycy 于 2013-3-6 08:57 编辑
  1. Sub 设置背景色()
  2.     Dim rg As Range
  3.     Dim blStart As Boolean
  4.     Dim lRow As Long, lCol As Long

  5.     For lRow = 1 To 11
  6.         For lCol = 24 To 70
  7.             Select Case blStart
  8.             Case True:
  9.                 If Len(Cells(lRow, lCol)) > 0 Then
  10.                     If rg Is Nothing Then
  11.                         Set rg = Cells(lRow, lCol)
  12.                     Else
  13.                         Set rg = Union(rg, Cells(lRow, lCol))
  14.                     End If

  15.                     If Len(Cells(lRow, lCol + 1)) = 0 Then
  16.                         blStart = False
  17.                     End If
  18.                 End If
  19.             Case False
  20.                 If Len(Cells(lRow, lCol)) > 0 And Len(Cells(lRow, lCol + 1)) > 0 Then
  21.                     If rg Is Nothing Then
  22.                         Set rg = Cells(lRow, lCol)
  23.                     Else
  24.                         Set rg = Union(rg, Cells(lRow, lCol))
  25.                     End If
  26.                     'Cells(lRow, lCol).Interior.ColorIndex = 3
  27.                     blStart = True
  28.                 End If
  29.             End Select
  30.         Next
  31.         
  32.         If blStart Then
  33.             If rg Is Nothing Then
  34.                 Set rg = Cells(lRow, lCol)
  35.             Else
  36.                 Set rg = Union(rg, Cells(lRow, lCol))
  37.             End If
  38.         End If
  39.         blStart = False
  40.     Next
  41.     rg.Interior.ColorIndex = 6
  42. End Sub
复制代码
回复

使用道具 举报

发表于 2013-3-6 08:55 | 显示全部楼层
本帖最后由 hwc2ycy 于 2013-3-6 08:57 编辑

我用的红色标注的,颜色要是不合适的话,直接改
  1. rg.Interior.ColorIndex = 3
复制代码
就成了。

黄色的已经设置了, 是
  1. rg.Interior.ColorIndex = 6
复制代码
回复

使用道具 举报

发表于 2013-3-6 08:56 | 显示全部楼层
  1. Sub 单元格底色()
  2.     Application.ScreenUpdating = False
  3.     取消底色
  4.     With Sheets("sheet1")
  5.         row1 = .Range("A" & .Rows.Count).End(xlUp).Row
  6.         For I = 1 To row1
  7.             For J = 24 To 118
  8.                 If .Cells(I, J) <> "" And .Cells(I, J + 1) <> "" Then
  9.                     .Cells(I, J).Interior.Color = 65535
  10.                     .Cells(I, J + 1).Interior.Color = 65535
  11.                 End If
  12.             Next
  13.         Next
  14.     End With
  15.     Application.ScreenUpdating = True
  16. End Sub
复制代码
回复

使用道具 举报

发表于 2013-3-6 08:58 | 显示全部楼层    本楼为最佳答案   
0个黄.rar (25.45 KB, 下载次数: 10)
回复

使用道具 举报

 楼主| 发表于 2013-3-6 12:41 | 显示全部楼层
zjdh 发表于 2013-3-6 08:58

非常感谢-----------------------------------------
回复

使用道具 举报

 楼主| 发表于 2013-3-6 12:43 | 显示全部楼层
hwc2ycy 发表于 2013-3-6 08:55
我用的红色标注的,颜色要是不合适的话,直接改就成了。

黄色的已经设置了, 是

f非常感谢------------------------------------
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-20 08:20 , Processed in 0.316102 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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