标题:本人菜鸟,请教一下,next 没有 for是什么原因,请大神帮忙改一下,谢谢。
只看楼主
dym258791731
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-4-28
结帖率:0
已结贴  问题点数:20 回复次数:6 
本人菜鸟,请教一下,next 没有 for是什么原因,请大神帮忙改一下,谢谢。
Sub s1()
 Dim rg As Range
 For Each rg In Range("d2:d176")
   If rg = "5335" Then
     rg = "一级"
   ElseIf rg = "4235" Then
     rg = "二级"
   ElseIf rg = "3828" Then
     rg = "三级"
   ElseIf rg = "3190" Then
     rg = "四级"
   ElseIf rg = "2937" Then
     rg = "五级"
   ElseIf rg = "2662" Then
     rg = "六级"
    If rg = "2431" Then
     rg = "七级"
   ElseIf rg = "2145" Then
     rg = "八级"
   ElseIf rg = "1881" Then
     rg = "九级"
   ElseIf rg = "1760" Then
     rg = "十级"
   ElseIf rg = "1661" Then
     rg = "十一级"
   ElseIf rg = "1639" Then
     rg = "十二级"
      ElseIf rg = "1529" Then
     rg = "十三级"
 End If
 Next rg
 
End Sub
搜索更多相关主题的帖子: next for 原因 If Then 
2017-04-28 10:50
wp231957
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:神界
等 级:版主
威 望:422
帖 子:13681
专家分:53296
注 册:2012-10-18
得分:5 
FOR EACH

DO IT YOURSELF !
2017-04-28 10:54
dym258791731
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-4-28
得分:0 
回复 楼主 dym258791731
还是运行不了啊!
2017-04-28 14:32
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4912
专家分:29900
注 册:2008-10-15
得分:5 
七级 的代码写错了。

这种的 If 块,建议用 Select case 来写,If 块太容易出错了。


授人于鱼,不如授人于渔
早已停用QQ了
2017-04-28 15:31
xzlxzlxzl
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:湖北
等 级:贵宾
威 望:125
帖 子:1091
专家分:5825
注 册:2014-5-3
得分:5 
那么多if没有对应的else造成的,你的代码应该这样写:
Sub s1()
  const c1="5335,4235,3828,3190,2937,2662,2431,2145,1881,1760,1760,1661,1639,1529"
  const c2="一级,二级,三级,四级,五级,六级,七级,八级,九级,十级,十一级,十二级,十三级"
  Dim rg As Range,b1() as string,b2() as string,i as integer
  For Each rg In Range("d2:d176")
    b1=split(c1,",")
    b2=split(c2,",")
    for i=0 to ubound(b1)
      if rg=b1(i) then
        rg=b2(i)
        exit for
      endif
    next
  next
end sub
2017-04-28 19:39
ZHRXJR
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:125
帖 子:1034
专家分:5519
注 册:2016-5-10
得分:5 
For Each rg In Range("d2:d176")
   If rg = "5335" Then
     rg = "一级"
   ElseIf rg = "4235" Then
     rg = "二级"
   ElseIf rg = "3828" Then
     rg = "三级"
   ElseIf rg = "3190" Then
     rg = "四级"
   ElseIf rg = "2937" Then
     rg = "五级"
   ElseIf rg = "2662" Then
     rg = "六级"
   ElseIf rg = "2431" Then    '这里缺少Else
     rg = "七级"
   ElseIf rg = "2145" Then
     rg = "八级"
   ElseIf rg = "1881" Then
     rg = "九级"
   ElseIf rg = "1760" Then
     rg = "十级"
   ElseIf rg = "1661" Then
     rg = "十一级"
   ElseIf rg = "1639" Then
     rg = "十二级"
      ElseIf rg = "1529" Then
     rg = "十三级"
 End If
 Next

请不要选我!!!
2017-04-28 21:01
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4912
专家分:29900
注 册:2008-10-15
得分:0 
回复5楼
split 应该在 for 之前

授人于鱼,不如授人于渔
早已停用QQ了
2017-04-28 23:12



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-476504-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.127844 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved