Excel精英培训网

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

[VBA] VBA这个代码错在哪里

[复制链接]
发表于 2016-11-7 09:13 | 显示全部楼层 |阅读模式

VBA这个代码错在哪里

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
发表于 2016-11-10 11:26 | 显示全部楼层
源代码错误部分详见红色部分:
Private Sub Worksheet_Change(ByVal Target As Range)
    On Error GoTo 100
    Dim mrow1 As Integer, mrow2 As Integer, mcol As Integer
    mrow1 = Target.Row
    If Target.Column = 1 And Len(Target) > 0 Then
        mrow2 = Range("h:h").Find(Target).Row
        mcol = Range("i" & mrow2).Interior.ColorIndex
        Range(Cells(mrow1, 1), Cells(mrow1, 3)).Interior.ColorIndex = mcol
    Else
        Range(Cells(mrow1, 1), Cells(mrow1, 3)).Interior.ColorIndex = 0
    End If
100:
    Range(Cells(mrow1, 1), Cells(mrow1, 3)).Interior.ColorIndex = 0

End Sub

评分

参与人数 1 +3 收起 理由
laoau138 + 3 来学习

查看全部评分

回复

使用道具 举报

发表于 2016-11-10 11:28 | 显示全部楼层
改正如下:
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2.     On Error GoTo 100
  3.     Dim mrow1 As Integer, mrow2 As Integer, mcol As Integer
  4.     mrow1 = Target.Row
  5.     If Target.Column = 1 And Len(Target) > 0 Then
  6.         mrow2 = Range("h:h").Find(Target).Row
  7.         mcol = Range("i" & mrow2).Interior.ColorIndex
  8.         Range(Cells(mrow1, 1), Cells(mrow1, 3)).Interior.ColorIndex = mcol
  9.     Else
  10. 100:
  11.         Range(Cells(mrow1, 1), Cells(mrow1, 3)).Interior.ColorIndex = 0
  12.     End If
  13. End Sub
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

评分

参与人数 2 +12 收起 理由
laoau138 + 3 来学习
望帝春心 + 9 神秘大神,我偷偷来学习了,哈哈~

查看全部评分

回复

使用道具 举报

 楼主| 发表于 2016-11-10 16:48 | 显示全部楼层

似乎在哪里见过你        有一点熟悉
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-6-4 15:23 , Processed in 1.380569 second(s), 8 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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