View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default formula through inputbox

Two ways, uncomment the second commented line to try the second way

Sub test()
Dim sFmla As String
Dim y As Variant

y = InputBox("enter formula")
If VarType(y) < vbBoolean Then ' user cancelled

sFmla = Replace("=IF(ISERROR(#~#),"""",#~#)", "#~#", y)

' sFmla = "=IF(ISERROR(" & y & "),""""," & y & ")"

ActiveCell.Formula = sFmla
End If

End Sub

Regards,
Peter T

"Utkarsh" wrote in message
...
Instead of entering a formula like =IF(ISERROR(C1/D1),"",C1/D1), I
would like the user the enter the formula like c1/d1 through an
inputbox. The code below tries to do this but is not working - the
results looks like =IF(ISERROR(y),"",y)


Sub Macro1()

y = InputBox("enter formula")

ActiveCell.Formula = "=IF(ISERROR(y),"""",y)"
End Sub