如果单元格值为0,则通过单元格L和字体红色并插入关系公式

时间:2015-12-16 01:07:52

标签: vba insert formula

所以一切正常,但vlookup部分。 vlookup的查找值不随单元格行移动。我不知道如何让“F& cell.number”与行一起移动。

Sub fontredd()
        Application.ScreenUpdating = False
        Application.Calculation = xlCalculationManual
        Dim rngL As range
        Dim cell As range

        Set rngL = range("L1", range("L65536").End(xlUp))
        For Each cell In rngL
            If cell.Value = "0" Then
                cell.EntireRow.Font.Color = vbRed
                cell.Formula = "=VLOOKUP(F&cell.number,[PickupCompaniesCommissions.xls]Sheet1!$U:$V,2,FALSE)"
            End If
        Next cell
        Application.ScreenUpdating = True
        Application.Calculation = xlCalculationAutomatic

    End Sub

1 个答案:

答案 0 :(得分:1)

cell.Formula = "=VLOOKUP(F" & cell.Row & ", [PickupCompaniesCommissions.xls]Sheet1!$U:$V,2,FALSE)"