首页 > 其他 > 详细

excle自编公式方法

时间:2014-03-24 15:14:59      阅读:461      评论:0      收藏:0      [点我收藏+]

操作很简单,工具-->巨集--》VB编辑器

选中 Microsoft 物件-->插入-->模组

下面的为一段代码,差不多明白怎么操作rang和返回。

不太清楚VBA是不是有点问题,我用checkCount="#??" return 这样的方式返回,有点问题,只能使用我强烈鄙视的goto才正常了 

bubuko.com,布布扣
Private Function checkCount(target As Range, countCell As Range, lookupRange As Range)

Dim cell  As Range
Dim xsum  As Double
Dim xval As Double
Dim result As String


If (VarType(countCell(1))) <> vbDouble Then
   result = "#??"
   GoTo 888
Else
   xval = countCell(1).Value
End If

Dim i As Integer
xsum = 0
i = 1
While (i < target.Count)
    If (VarType(target(i)) = vbDouble) Then
        xsum = xsum + target(i).Value
        If (xval <= xsum) Then
           If (lookupRange.Count < i) Then
              result = "#???"
              GoTo 888
           Else
              result = lookupRange(i).Value
              GoTo 888
           End If
        End If
    End If
    i = i + 1
Wend

888:
  checkCount = result

End Function
bubuko.com,布布扣

excle自编公式方法,布布扣,bubuko.com

excle自编公式方法

原文:http://www.cnblogs.com/wonder223/p/3620473.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!