繁体   English   中英

VBA中的间接匹配公式

[英]Indirect Match formula within VBA

我很难将公式加入VBA

这是公式:

=INDEX('Raw G'!1:1048576,MATCH(N5,INDIRECT("'Raw G'!" & ToColletter(MATCH(F4,'Raw G'!2:2,0))&":"&ToColletter(MATCH(F4,'Raw G'!2:2,0))),0),MATCH("Grand Total*",'Raw G'!3:3,0)+1)

我需要使用以下标准将它应用于L行下的每个单元:

Sub csku()

With Application
    Set SrchRng = .Range(.Cells(4, "N"), .Cells(Rows.Count, "N").End(xlUp))

    For Each cel In SrchRng
        If cel.Value2 > 0 Then
            cel.Offset(0, -2).Value = 

End With

End Sub

但是,我不太确定该怎么做,因为它在公式中包含多个公式。

另外,我使用一个应用程序将数字转换为列字母:

Public Function ToColletter(Collet)
ToColletter = Split(Cells(1, Collet).Address, "$")(1)
End Function

非常感谢您的帮助。

对于您的公式,最好使用INDEX而不是INDIRECT。

=if(n4>0, index('Raw G'!A:XFC, match(n5, index('Raw G'!A:XFC, 0, match(f4, 'Raw G'!$2:$2, 0)), 0), match("Grand Total*", 'Raw G'!$3:$3, 0)+1), text(,))

然后将其应用于“具有以下一组标准的每个L单元中的每个单元”

Sub csku()
    dim f as string

    With worksheets("sheet1")
        with .Range(.Cells(4, "L"), .Cells(Rows.Count, "N").End(xlUp).Offset(0, -2))
                       'double-up quotes within a quoted string
            .formula = "=if(n4>0, index('Raw G'!A:XFC, match(n5, index('Raw G'!A:XFC, 0, match(f4, 'Raw G'!$2:$2, 0)), 0), match(""Grand Total*"", 'Raw G'!$3:$3, 0)+1), text(,))"
            'optionally convert formula results to values
            '.value = .value
        end with
    End With
End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM