Excel精英培训网

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

[已解决]代码不够到位,少了一个条件,求大神帮忙完善,感谢了先

[复制链接]
发表于 2015-6-16 10:45 | 显示全部楼层 |阅读模式
本帖最后由 eking_tang 于 2015-6-16 11:26 编辑

逻辑大概想到了,可是代码写不出来,求大神们帮忙了,感谢大家先
最佳答案
2015-6-16 11:21
  1. For b = 8 To Cells(Rows.Count, "a").End(3).Row
  2.     If IsError(Range("ax" & b)) Then
  3.         Cells(b, 1) = 0
  4.     Else
  5.         xx = Range("ax" & b)
  6.         j = IIf(Cells(b, "L") <> "", 12, Cells(b, "L").End(xlToRight).Column) '从L列开始找b行第一个非空列
  7.         If Cells(b - 2, j) = "" Then       '非空列b-2行为空
  8.             Cells(b, 1) = Cells(b, 1) / xx * 0.041666 + n
  9.         Else                              '非空列b-2行不为空
  10.             Cells(b, 1) = Cells(b, 1) / xx * 0.041666 + Cells(b - 1, 1)
  11.         End If
  12.     End If
  13. Next
复制代码

SC10~SC17 DPS for 11111111.zip

103.95 KB, 下载次数: 5

发表于 2015-6-16 11:02 | 显示全部楼层
For b = 8 To Cells(Rows.Count, "a").End(3).row
    If IsError(Range("ax" & b)) Then
        Cells(b, 1) = 0
    Else
        xx = Range("ax" & b)
        j = IIf(Cells(b, "L") <> "", 12, Cells(b, "L").End(xlToRight).Column) '从L列开始找b行第一个非空列
        If Cells(b - 2, j) = "" Then       '非空列b-2行为空
            Cells(b, 1) = Cells(b, 1) / xx * 0.041666 + n
        Else                              '非空列b-2行不为空
            Cells(b, 1) = Cells(b, 1) / xx * 0.041666 + Cells(b - 1, 1)
    End If
Next

评分

参与人数 1 +3 收起 理由
eking_tang + 3 赞一个!

查看全部评分

回复

使用道具 举报

 楼主| 发表于 2015-6-16 11:14 | 显示全部楼层
grf1973 发表于 2015-6-16 11:02
For b = 8 To Cells(Rows.Count, "a").End(3).row
    If IsError(Range("ax" & b)) Then
        Cells( ...

麻烦再帮忙看看~不知道为什么会提示说有NEXT,没有FOR呢???
回复

使用道具 举报

发表于 2015-6-16 11:21 | 显示全部楼层
next 上面少了个 endif。。。。。

评分

参与人数 1 +3 收起 理由
eking_tang + 3 赞一个!

查看全部评分

回复

使用道具 举报

发表于 2015-6-16 11:21 | 显示全部楼层    本楼为最佳答案   
  1. For b = 8 To Cells(Rows.Count, "a").End(3).Row
  2.     If IsError(Range("ax" & b)) Then
  3.         Cells(b, 1) = 0
  4.     Else
  5.         xx = Range("ax" & b)
  6.         j = IIf(Cells(b, "L") <> "", 12, Cells(b, "L").End(xlToRight).Column) '从L列开始找b行第一个非空列
  7.         If Cells(b - 2, j) = "" Then       '非空列b-2行为空
  8.             Cells(b, 1) = Cells(b, 1) / xx * 0.041666 + n
  9.         Else                              '非空列b-2行不为空
  10.             Cells(b, 1) = Cells(b, 1) / xx * 0.041666 + Cells(b - 1, 1)
  11.         End If
  12.     End If
  13. Next
复制代码

评分

参与人数 1 +3 收起 理由
eking_tang + 3 我能不能说一句:爱死你了.问题完美解决,太感.

查看全部评分

回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-20 19:05 , Processed in 0.259841 second(s), 15 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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