How to concatenate variable with formula in Excel?

0

Is it correct for me to concatenate a variable to an Excel formula?

Excel complains about closing the concatenation:

Sheets("FATURA").Select
Dim variavel As Double
variavel = InputBox("Digite Valor da Tarifa caso nao souber Digite 0,35")               
MsgBox ("Valor sem desconto: " & variavel)
Range("Z2:Z" & Range("I1048576").End(xlUp).Row).Formula = "=RC[-1]&IF(RC[-2]< " &variavel& ,""M"",""O"")"  
    
asked by anonymous 13.04.2017 / 21:57

1 answer

1

Marcio, good afternoon!

In my vision yes is possible and this is right, because it becomes necessary according to your need for dynamism in building the formula. So here is my suggestion of how I think it will work:

Sheets("FATURA").Select

Dim variavel As Double

variavel = InputBox("Digite Valor da Tarifa caso não souber Digite 0,35")               

MsgBox ("Valor sem desconto: " & variavel)

Range("Z2:Z" & Range("I1048576").End(xlUp).Row).Formula = "=RC[-1]&IF(RC[-2]< " & variavel & ," & chr(34) & "M" & chr34) & "," & chr(34) & "O" & chr(34) & ")" 
    
14.04.2017 / 20:55