简体   繁体   English

VBA中的间接匹配公式

[英]Indirect Match formula within VBA

I'm having a hard time trying to get my formula into VBA 我很难将公式加入VBA

This is the formula: 这是公式:

=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)

I need it to apply on every cell down row L with the following set of criteria: 我需要使用以下标准将它应用于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

However, I'm not too sure how I can go about doing this, as it contains multiple formulas in formulas. 但是,我不太确定该怎么做,因为它在公式中包含多个公式。

In addition, I use an application to convert number to column letter: 另外,我使用一个应用程序将数字转换为列字母:

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

Much help is appreciated. 非常感谢您的帮助。

It may be better to use INDEX instead of INDIRECT for your formula. 对于您的公式,最好使用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(,))

Then apply it to every 'every cell down row L with the following set of criteria' . 然后将其应用于“具有以下一组标准的每个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