How to concatenate variable with formula in Excel?

Asked

Viewed 4,369 times

0

It is correct that I concatenate a variable to an Excel formula?

Excel complains at concatenation closure:

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"")"  
  • I tried to format your code, but I have no idea if it’s right. You can click [Edit] and format it.

1 answer

1

Marcio, good afternoon!

In my view it is possible and this certain, because it is necessary according to its need of dynamism when building the formula. So follow my suggestion of how I believe 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) & ")" 
  • Nice friend I’ll try

  • I played Result in a cell and made the calculation from the same q solved my problem

Browser other questions tagged

You are not signed in. Login or sign up in order to post.