Excel精英培训网

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

[已解决]老师们,帮忙看一下我的代码哪里出错了,谢谢

[复制链接]
发表于 2015-6-13 16:32 | 显示全部楼层 |阅读模式
本帖最后由 haohaizi007 于 2015-6-16 19:32 编辑

  我那个问题2,我自己查了一下,编了一段代码,但是运行的时候显示
对象 _default 的方法 Range 失败  
请老师们指点一下该怎么做。 谢谢  

Sub 宏5()
'
'宏5 宏
Dim i As Integer
For i = 4 To 429

If Cells(R, i) = "√" Or "△" Then
     Cells(T, i) = "12"
     End If
If Cells(R, i) = "" Then
     Cells(T, i) = "11"
          End If
If Cells(Q, i) = "" Then
     Cells(T, i) = "10"
          End If
           If Cells(P, i) = "" Then
     Cells(T, i) = "9"
          End If
           If Cells(O, i) = "" Then
     Cells(T, i) = "8"
          End If
           If Cells(N, i) = "" Then
     Cells(T, i) = "7"
          End If
           If Cells(M, i) = "" Then
     Cells(T, i) = "6"
          End If
           If Cells(L, i) = "" Then
     Cells(T, i) = "5"
          End If
           If Cells(K, i) = "" Then
     Cells(T, i) = "4"
          End If
           If Cells(J, i) = "" Then
     Cells(T, i) = "3"
          End If
           If Cells(i, i) = "" Then
     Cells(T, i) = "2"
          End If
           If Cells(H, i) = "" Then
     Cells(T, i) = "1"
          End If
           If Cells(G, i) = "" Then
     Cells(T, i) = "0"
          End If
     Next

End Sub

最佳答案
2015-6-13 17:12
haohaizi007 发表于 2015-6-13 16:56
感谢老师回复。

按照老师指点,改成

If Cells(i, "R") = "√" Or cells(i,"R")="△" Then
改成这样

工作簿1.zip

24.53 KB, 下载次数: 1

发表于 2015-6-13 16:39 | 显示全部楼层
cells(行,列),行列是数字和变量的不用引号的,字母就要加引号
回复

使用道具 举报

 楼主| 发表于 2015-6-13 16:56 | 显示全部楼层
qh8600 发表于 2015-6-13 16:39
cells(行,列),行列是数字和变量的不用引号的,字母就要加引号

感谢老师回复。

按照老师指点,改成

Sub 宏5()
'
'宏5 宏
Dim i As Integer
For i = 4 To 429

If Cells(i, "R") = "√" Or "△" Then
     Cells(i, "T") = "12"
     End If
If Cells(i, "R") = "" Then
     Cells(i, "T") = "11"
          End If
If Cells(i, "Q") = "" Then
     Cells(i, "T") = "10"
          End If
           If Cells(i, "P") = "" Then
     Cells(i, "T") = "9"
          End If
           If Cells(i, "O") = "" Then
     Cells(i, "T") = "8"
          End If
           If Cells(i, "N") = "" Then
     Cells(i, "T") = "7"
          End If
           If Cells(i, "M") = "" Then
     Cells(i, "T") = "6"
          End If
           If Cells(i, "L") = "" Then
     Cells(i, "T") = "5"
          End If
           If Cells(i, "K") = "" Then
     Cells(i, "T") = "4"
          End If
           If Cells(i, "J") = "" Then
     Cells(i, "T") = "3"
          End If
           If Cells(i, "I") = "" Then
     Cells(i, "T") = "2"
          End If
           If Cells(i, "H") = "" Then
     Cells(i, "T") = "1"
          End If
           If Cells(i, "G") = "" Then
     Cells(i, "T") = "0"
          End If
     Next

End Sub



运行时候出现  类型不匹配

点击调试 红色字体标成了黄色。
回复

使用道具 举报

发表于 2015-6-13 17:12 | 显示全部楼层    本楼为最佳答案   
haohaizi007 发表于 2015-6-13 16:56
感谢老师回复。

按照老师指点,改成

If Cells(i, "R") = "√" Or cells(i,"R")="△" Then
改成这样
回复

使用道具 举报

 楼主| 发表于 2015-6-13 17:17 | 显示全部楼层
qh8600 发表于 2015-6-13 17:12
If Cells(i, "R") = "√" Or cells(i,"R")="△" Then
改成这样

完美解决,非常感谢您的指导。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-14 04:31 , Processed in 0.227113 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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