jeudi 25 février 2021

How can I convert this IF statement to use in VBA

I have the following IF statement =IF(LEN(F2)>LEN(H2),F2,H2)

This just checks which is longer between F2 and H2 and populates I2 with the longest. When I put this in VBA it comes out as =IF(LEN(G1048558)>LEN(I1048558),G1048558,I1048558)in my spreadsheet

How could I fix this?

Sub PopulateI()

Range("I2").Select
ActiveCell.FormulaR1C1 = _
"=IF(LEN(R[-20]C[-2])>LEN(R[-20]C),R[-20]C[-2],R[-20]C)"
Selection.AutoFill Destination:=Range("I2:I" & Range("F" & Rows.Count).End(xlUp).Row)

End Sub

Aucun commentaire:

Enregistrer un commentaire