Apply IF condition to a range Excel VBA
问题 I have written this code but it doesnt seems to be working , Why? Dim oRo As String Dim nRo As String Lastro = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row oRo = "J2:O" & Lastro nRo = "Q2:V" & Lastro Range("C2:G" & Lastro).Select With Range("C2:G" & Lastro) .Range("C2:G" & Lastro).Formula = "=IF(oRo*nRo<0,ROUNDUP(oRo*1.3,-2),IF(ABS(oRo) <=ABS(nRo),nRo,ROUNDUP(oRo*1.3,-2)))" End With End Sub 回答1: Your best bet for maintainability is to embrace R1C1 notation when you write formulas to Excel