Inputbox and pass values to a formula in an another Workbook

  • Thread starter Thread starter stakar
  • Start date Start date
S

stakar

At first, i want to create this in a cell e.g. 'D3'

IF($A3="";"";IF(OR(C3=1;C3=12;C3=18;C3=40);1;0))
The formula is locating in the cell D3, workbook A, worksheet 1

But
i want the cell values to be inserted from the user using an inputbox
that he must insert something like this

14.5.12.45.1 etc

The inputbox will appears when a command_button clicks
and it is lockated in workbook B, worksheet 1

So
The above values would be the values for each 'C3=' for the formula
So, using the inserted by the user values, the formula would be

IF($A3="";"";IF(OR(C3=14;C3=5;C3=12;C3=45;C3=1);1;0))

Hope you understand
Thanks in advance
Stathi
 
One of the nice things about excel is the way you can accomplish the same thing
with a different technique:

For instance, your formula:
=IF($A3="";"";IF(OR(C3=14;C3=5;C3=12;C3=45;C3=1);1;0))

Could be rewritten as:
=IF($A3="";"";IF(OR(C3={14,5,12,45,1});1;0))

Now, you only have to check to see if that string is numeric and then just plop
it in the formula:

Option Explicit
Sub testme()

Dim myCell As Range
Dim myStr As String

Set myCell = Worksheets("sheet1").Range("d3")

myStr = InputBox(Prompt:="What're the numbers?")

If IsNumeric(Application.Substitute(myStr, ".", "")) = False Then
MsgBox "Not Valid!"
Exit Sub
End If

myCell.Formula = "=IF($A3="""","""",IF(OR(C3={" & _
Application.Substitute(myStr, ".", ",") & "}),1,0))"

End Sub
 
Dave said:
*One of the nice things about excel is the way you can accomplish th
same thing
with a different technique:

For instance, your formula:
=IF($A3="";"";IF(OR(C3=14;C3=5;C3=12;C3=45;C3=1);1;0))

Could be rewritten as:
=IF($A3="";"";IF(OR(C3={14,5,12,45,1});1;0))

Now, you only have to check to see if that string is numeric and the
just plop
it in the formula:

Option Explicit
Sub testme()

Dim myCell As Range
Dim myStr As String

Set myCell = Worksheets("sheet1").Range("d3")

myStr = InputBox(Prompt:="What're the numbers?")

If IsNumeric(Application.Substitute(myStr, ".", "")) = False Then
MsgBox "Not Valid!"
Exit Sub
End If

myCell.Formula = "=IF($A3="""","""",IF(OR(C3={" & _
Application.Substitute(myStr, ".", ",") & "}),1,0))"

End Sub

Dave
Thanks a lot for your both solutions!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top