Excel精英培训网

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

[已解决]求教VBA代替规则

[复制链接]
发表于 2014-6-10 09:41 | 显示全部楼层 |阅读模式
大家好,我的excel文档运行很慢,我用这个表格半年大概要有2000行,已经换过一个表了,之前的表也是运行起来太慢,插入一行等很久。现在新表也出现问题了。但是,现在老表又变得流畅了,不知道为什么。
需要向大家求助的是:
高手帮我看看能不能用VBA代替现有公式。当我在F列输上“chargeable ”时,该单元格要变绿,同时G列自动变成“NY”。当填上“Paid”时,该横行整体变成蓝色。

多谢!

最佳答案
2014-6-10 10:13
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2.     If Target.Column = 6 Then
  3.         If Target.Cells(1, 1) = "Chargeable" Then
  4.             Target.Cells(1, 1).Interior.ColorIndex = 50
  5.             Target.Cells(1, 2) = "NY"
  6.         End If
  7.     End If
  8.     If Target.Column = 8 Then
  9.         Rows(Target.Row).Interior.ColorIndex = 34
  10.     End If
  11. End Sub
复制代码
test.rar (187.76 KB, 下载次数: 22)

test.zip

182.58 KB, 下载次数: 3

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2014-6-10 09:52 | 显示全部楼层
看到chargeable时有些G列为NY,有些为YES,效果体现出来看下
回复

使用道具 举报

发表于 2014-6-10 10:13 | 显示全部楼层    本楼为最佳答案   
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2.     If Target.Column = 6 Then
  3.         If Target.Cells(1, 1) = "Chargeable" Then
  4.             Target.Cells(1, 1).Interior.ColorIndex = 50
  5.             Target.Cells(1, 2) = "NY"
  6.         End If
  7.     End If
  8.     If Target.Column = 8 Then
  9.         Rows(Target.Row).Interior.ColorIndex = 34
  10.     End If
  11. End Sub
复制代码
test.rar (187.76 KB, 下载次数: 22)
回复

使用道具 举报

 楼主| 发表于 2014-6-11 07:21 | 显示全部楼层
cpq151721 发表于 2014-6-10 09:52
看到chargeable时有些G列为NY,有些为YES,效果体现出来看下

谢谢回复,你什么意思我没有看懂。。。
回复

使用道具 举报

 楼主| 发表于 2014-6-11 07:46 | 显示全部楼层
qh8600 发表于 2014-6-10 10:13

太感谢你的指导啦!有两个问题,一个是运行这个VBA之后,之前那些是不是自动运行啊?第二个是白色的代码是多少?
回复

使用道具 举报

发表于 2014-6-11 08:49 | 显示全部楼层
甜菜赫 发表于 2014-6-11 07:46
太感谢你的指导啦!有两个问题,一个是运行这个VBA之后,之前那些是不是自动运行啊?第二个是白色的代码是 ...

http://wenku.baidu.com/view/c6b024dcce2f0066f53322b3.html
vba 颜色代码 数字可以参考上面的帖子,白色=2
回复

使用道具 举报

 楼主| 发表于 2014-6-11 09:35 | 显示全部楼层
qh8600 发表于 2014-6-11 08:49
http://wenku.baidu.com/view/c6b024dcce2f0066f53322b3.html
vba 颜色代码 数字可以参考上面的帖子,白 ...

谢谢。
我想设置一下如果F列为chargeable的话,G为NY,HIJ3列都为“-”,下面的代码对吗?我试了一下,运行起来颜色有的有有的没有,而且在F输入chargeable之后需要点一下后面才能出来呢。

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Column = 6 Then
        If Target.Cells(1, 1) = "Chargeable" Then
            Target.Cells(1, 1).Interior.ColorIndex = 50
            Target.Cells(1, 2) = "NY"
            
            Target.Cells(1, 3) = "-"
            
            Target.Cells(1, 4) = "-"
            
            Target.Cells(1, 5) = "-"
        End If
    End If
    If Target.Column = 8 Then
        Rows(Target.Row).Interior.ColorIndex = 2
    End If

End Sub
回复

使用道具 举报

 楼主| 发表于 2014-6-16 18:02 | 显示全部楼层
qh8600 发表于 2014-6-11 08:49
http://wenku.baidu.com/view/c6b024dcce2f0066f53322b3.html
vba 颜色代码 数字可以参考上面的帖子,白 ...

请问,你知道有没有什么办法可以取代我后面的link?

我就是把PDF放在公司公共硬盘,做个link可以打开看,有什么更好的办法吗?

多谢!
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-6-1 04:43 , Processed in 0.706415 second(s), 12 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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