[算表] 无法取得worksheetfunction的MATCH属性

楼主: jimmy0413 (小M&小I)   2016-03-24 01:52:25
软件:EXCEL
VBA
版本:2010
这是我的VBA程式码,不知道为何在
"sumup = Application.WorksheetFunction.Index(tponumberrow, 1,
Application.WorksheetFunction.Match(vatoprange1, pricerow, 0)) +
Application.WorksheetFunction.Index(tponumberrow, 1,
Application.WorksheetFunction.Match(vatoprange2, pricerow, 0))"
一直出现出现错误"无法取得worksheetfunction的MATCH属性"
试了超级九还是不知道是哪里出了问题,有人可以帮我看一下吗><
以下是我的程式码
Sub 算VA()
Dim tponumberrow, abc As Range
Dim pricerow, bcd As Range
Dim varange()
Dim tponumber As Integer
Dim sumup As Integer
Dim sumdown As Integer
tponumberrow = Worksheets("运算").Range("c3:ST3")
pricerow = Worksheets("运算").Range("c4:ST4")
varange = Array(Worksheets("运算").Range("d2").Value)
Do While tponumber <= Worksheets("运算").Range("J2").Value * 0.7
Dim maxvarange As Integer
Dim minvarange As Integer
maxvarange = varange(LBound(varange))
minvarange = varange(LBound(varange))
For i = LBound(varange) + 1 To UBound(varange)
If maxvarange < varange(i) Then maxvarange = varange(i)
Next i
For i = LBound(varange) + 1 To UBound(varange)
If minvarange > varange(i) Then minvarange = varange(i)
Next i
Dim vatoprange1, vatoprange2, vabottomrange1, vabottomrange2 As Integer
vatoprange1 = maxvarange + 2
vatoprange2 = maxvarange + 1
vabottomrange1 = minvarange - 2
vabottomrange2 = minvarange - 1
sumup = Application.WorksheetFunction.Index(tponumberrow, 1,
Application.WorksheetFunction.Match(vatoprange1, pricerow, 0)) +
Application.WorksheetFunction.Index(tponumberrow, 1,
Application.WorksheetFunction.Match(vatoprange2, pricerow, 0))
sumdown = Application.WorksheetFunction.Index(tponumberrow, 1,
Application.WorksheetFunction.Match(vabottomrange1, pricerow, 0)) +
Application.WorksheetFunction.Index(tponumberrow, 1,
Application.WorksheetFunction.Match(vabottomrange2, pricerow, 0))
For i = LBound(varange) + 1 To UBound(varange)
If maxvarange < varange(i) Then maxvarange = varange(i)
Next i
For i = LBound(varange) + 1 To UBound(varange)
If minvarange > varange(i) Then minvarange = varange(i)
Next i
If sumup > sumdown Then
varange(LBound(varange) + 1) = maxvarange + 1
varange(LBound(varange) + 2) = maxvarange + 2
End If
Loop
MsgBox (maxvarange)
End Sub
非常不好意思我是初学者,也没有人可以询问,所以只能上来这边问了,
有人能够帮忙的话我会非常感激的QQ
作者: soyoso (我是耀宗)   2016-03-24 08:01:00
是否vatoprange1或vatoprange2的值于pricerow array内是找不到呢?https://imgur.com/4c62fVo 测试如有值时是可以执行的当找不到值时则出现如原文的错误https://imgur.com/TOgHztL另外dim宣告可不写于循环内;如要将vatoprange1、vatoprange2,vabottomrange1,vabottomrang2宣告为integer时,写法需个别指定tponumber无看到累加,会有无穷循环的可能^^^^累加减

Links booklink

Contact Us: admin [ a t ] ucptt.com