application.match vba十进制数上的错误2042

时间:2017-06-16 14:16:06

标签: excel vba excel-vba runtime-error

我无法将范围的最大值匹配到相同的范围内。这样做的目的是知道哪个列可以找到最大值。

我正在尝试使用此代码

    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属性

1 个答案:

答案 0 :(得分:0)

Select distinct i.* FROM [dbo].[Imported] i inner join [DaisyCompare].[dbo].[Baseline] b on b.[CLI] = i.[CLI] and b.[Quantity] = i.[Quantity] and b.[UnitCost] = i.[UnitCost] and b.[TotalCost] = i.[TotalCost] and b.[Description] = i.[Description] 转换为Long Integer,基本上会删除任何小数。使用CLng转换为双倍。

CDbl

您还在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 中留下了一些悬空细胞参考,我试图将其收紧。