Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default formula through inputbox

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default formula through inputbox

If you use the Application.InputBox method (check it out in help; it is
different then InputBox Function) then you can set the Type to zero which
allows formula input.

ActiveCell = Application.InputBox(Prompt:="Enter formula", Type:=0)

With above you can enter =IF(ISERROR(C1/D1),"",C1/D1) directly into the
Application.InputBox


--
Regards,

OssieMac


"Utkarsh" wrote:

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
.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default formula through inputbox

I think, or rather guess as it's not clear at all, the OP's objective is
simply to enter [say] "C1/D1" without quotes as the variable element of the
long formula which eventually needs to be applied to the cell's formula. If
so both the VBA and Excel Inputbox would work fine.

Regards,
Peter T

"OssieMac" wrote in message
...
If you use the Application.InputBox method (check it out in help; it is
different then InputBox Function) then you can set the Type to zero which
allows formula input.

ActiveCell = Application.InputBox(Prompt:="Enter formula", Type:=0)

With above you can enter =IF(ISERROR(C1/D1),"",C1/D1) directly into the
Application.InputBox


--
Regards,

OssieMac


"Utkarsh" wrote:

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
.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default formula through inputbox

Re-reading the question I think you are probably correct Peter.

In which case using Application.InputBox the Type should be 2 for a string
and then use one of your methods to create the formula final formula.

Dim y As String

y = Application.InputBox(Prompt:="Enter Formula", Type:=2)

ActiveCell.Formula = "=IF(ISERROR(" & y & "),""""," & y & ")"

--
Regards,

OssieMac



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
InputBox James8309 Excel Programming 2 June 17th 08 08:02 AM
Inputbox for a formula FARAZ QURESHI Excel Discussion (Misc queries) 0 February 29th 08 09:19 AM
InputBox value in formula problem COV MarshallT Excel Programming 3 August 31st 07 06:59 PM
Value in a inputbox Alvin Hansen[_2_] Excel Programming 3 February 22nd 05 08:15 PM
Inputbox and Application.InputBox Maria[_7_] Excel Programming 1 September 20th 04 11:36 AM


All times are GMT +1. The time now is 11:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"