简体   繁体   中英

Indirect Match formula within VBA

I'm having a hard time trying to get my formula into 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:

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.

=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' .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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