Variables in VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

A while back someone helped me write this code. Basicall someone inputs a
text string like '4+5 in cell A2 and in another cell you type =qwerty() and
the result is 9 (for the example given anyways). How do I change the formula
to accept a cell reference. For instance I want it to be =qwerty(F4) to look
at the text in F4.

Function qwerty()
Dim s As String
s = Cells(2, 1)
qwerty = Evaluate(s)
End Function
 
Hi,
Try:

In your example, in B2 put "=qwerty(a2)"

Function qwerty(ByVal rng As Range) As Double
qwerty = Evaluate(rng.Value)
End Function
 
Function qwerty(rng As Range)
If rng.Count = 1 Then
qwerty = Evaluate(rng.Value)
End If
End Function

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Thanks guys,

I couldn't get your code to work Toppers. I keep getting a #VALUE error in
the cell unless I delete "As Double". What is that supposed to do? And what
does the "ByVal" do?
 

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