Home > Software engineering >  Writing multi-line formula to range using VBA
Writing multi-line formula to range using VBA

Time:04-04

Desired result in the formula bar:

=IF(True,
1,0)

These return generic 1004 error:

Selection.Formula = "=IF(True," & vbCrLf & "1,0)"
Selection.Formula = "=IF(True," & vbNewLine & "1,0)"

Selection.Formula = "=IF(True," & CHAR(10) & "1,0)" (edited as Chr(10) does actually work, thanks Tim)

Is there any possible workaround to get a new line in the formula bar?

CodePudding user response:

It appears that the formula bar supports only LF character, but it is possible:

selection.formula = "=IF(True," & vbLf & "1,0)"

As Tim pointed out in a comment above, this also works:

selection.formula = "=IF(True," & Chr(10) & "1,0)"
  • Related