Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default Variables in VBA

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Variables in VBA

Hi,
Try:

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

Function qwerty(ByVal rng As Range) As Double
qwerty = Evaluate(rng.Value)
End Function

"Sloth" wrote:

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default Variables in VBA

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?

"Toppers" wrote:

Hi,
Try:

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

Function qwerty(ByVal rng As Range) As Double
qwerty = Evaluate(rng.Value)
End Function

"Sloth" wrote:

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Variables in VBA

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)


"Sloth" wrote in message
...
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




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
Not at all clear on use of variables and/or object variables JMay-Rke Excel Discussion (Misc queries) 11 July 4th 08 06:36 PM
Using variables . . . Wayne Knazek Excel Discussion (Misc queries) 2 July 6th 06 05:01 PM
How do I Sum variables Novaloc Excel Programming 3 October 13th 05 08:00 AM
Variables Phil Excel Programming 1 April 15th 05 04:39 PM
Variables Tim U[_2_] Excel Programming 2 June 22nd 04 10:12 PM


All times are GMT +1. The time now is 07:28 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"