【发布时间】:2009-09-18 20:37:33
【问题描述】:
我在 excel 中创建了一个函数,它基本上在 For 语句中的动态范围内搜索字符串并返回一列上单元格的值。它基本上是一个预算功能,但这不是重点。
这就是问题所在,一切都适用于小的结果,但是当结果变得太大(比如大约 32000... 出于某种原因似乎是数字)时,函数开始返回 0。
有人遇到过这样的问题吗?
这是有问题的代码:
Function Material(item As String, Optional sheetType As String) As Integer
Dim wSheet As Worksheetr
Dim count As Integer
Dim offSet As Integer
Dim ref As Integer
Dim bottomRight As Integer
Dim upperLeft As Integer
Dim rng As Range
Dim cVal As Integer
For Each wSheet In Worksheets
If wSheet.Name = "Drywall Pricing" Then
dwIndex = wSheet.Index - 1
End If
Next wSheet
If IsMissing(sheetType) Then
sheetType = " "
Else
sheetType = UCase(sheetType)
End If
For i = 1 To dwIndex
wSheetName = Sheets(i).Name
If InStr(UCase(wSheetName), sheetType) > 0 Then
count = 9
offSet = 44
ref = 27
For wall = 0 To count - 1
On Error Resume Next
Err.Clear
upperLeft = (ref + 12) + (offSet * wall)
bottomRight = (ref + 30) + (offSet * wall)
Set rng = Sheets(i).Range("A" & upperLeft & ":B" & bottomRight)
cVal = Application.WorksheetFunction.VLookup(item, rng, 2, False)
If Err.Number > 0 Then
cVal = 0
End If
units = units + cVal
Next wall
Else
units = units + 0
End If
Next i
If units > 0 Then
Material = units
Else
Material = 0
End If
End Function
我设置了一个电子表格来手动计算一定数量的项目(即“=A13+B5+B26”等),并将其与运行相关函数的结果进行比较,当结果较低时,它们彼此相等,所以我知道函数本身工作正常。那么这是内存问题吗?
任何帮助将不胜感激。
提前致谢!
【问题讨论】:
-
你为什么不调暗单位?
-
不...这是我的错误。