VBA Range.Formula问题

时间:2018-05-27 13:33:06

标签: excel vba excel-formula

我对excel VBA上的range.formula感到困惑, 我试着在我的VBA代码中使用公式RIGHT

LR = Cells(Rows.Count, "A").End(xlUp).Row

For i = 1 To LR
    cel = "A" & i
    cel2 = "P" & i
    cel3 = "Q" & i
    Range("R" & i).Formula = "=RIGHT("cel", "cel2" & "" - "" & "cel3")"

我的代码的最后一行,我尝试right(A1, P1-Q1) 但是,我得到语法错误,我正在努力解决

提前致谢

1 个答案:

答案 0 :(得分:1)

你非常非常接近:

Sub marine()
    LR = Cells(Rows.Count, "A").End(xlUp).Row

    For i = 1 To LR
        cel = "A" & i
        cel2 = "P" & i
        cel3 = "Q" & i
        Range("R" & i).Formula = "=RIGHT(" & cel & "," & cel2 & " - " & cel3 & ")"
    Next i
End Sub

enter image description here