[英]Error 2042 on application.match vba decimal numbers
我無法將范圍的最大值匹配到相同的范圍內。 這樣做的目的是知道哪個列可以找到最大值。
我正在嘗試使用此代碼
Set rango = Range(Cells(45, W), Cells(46, W1))
rango.Select
maximo = WorksheetFunction.Max(rango)
matching = Application.Match(CLng(maximo), Sheets("Dinamicos").Range(Cells(45, W), Cells(46, W1)), 0)
但我得到了2042錯誤。 在本節中我試圖匹配百分比,如果我使用代碼
Set rango = Range(Cells(45, W), Cells(46, W1))
rango.Select
maximo = WorksheetFunction.Max(rango)
matching = WorksheetFunction.Match.Match(CLng(maximo), Sheets("Dinamicos").Range(Cells(45, W), Cells(46, W1)), 0)
我得到運行時錯誤1004無法獲取WorksheetFunction的Match屬性
CLng
轉換為Long Integer,基本上會刪除任何小數。 使用CDbl
轉換為double。
dim maximo as double, matching as variant
with worksheets("sheet1")
maximo = WorksheetFunction.Max(.Range(.Cells(45, W), Cells(.46, W1)))
end with
with worksheets("Dinamicos")
matching = Application.Match(CDbl(maximo), .Range(.Cells(45, W), .Cells(46, W)), 0)
if not iserror(matching) then
'found a match in W; do something
debug.print "found in W"
else
matching = Application.Match(CDbl(maximo), .Range(.Cells(45, W1), .Cells(46, W1)), 0)
if not iserror(matching) then
'found a match in W1; do something
debug.print "found in W1"
end if
end if
end with
你還在Sheets("Dinamicos").Range(Cells(45, W), Cells(46, W1))
留下了一些懸空細胞參考Sheets("Dinamicos").Range(Cells(45, W), Cells(46, W1))
我試圖Sheets("Dinamicos").Range(Cells(45, W), Cells(46, W1))
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.