Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / January 2008

Tip: Looking for answers? Try searching our database.

Help with compile error?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
newbie - 04 Jan 2008 03:59 GMT
I wonder if some one can tell me what is wrong with my code?
I am having problems with the first line? I looked online and i
thought my syntax was correct?

Andrew

Function Process1(Reactant As Real, Yield As Real) As Real

Dim Reactant As Real
Dim Yield As Real

Set Cresult2 = 0

'Do

Set Reactant = Workbooks("Sayaka").Sheets("Sheet1").Range("D34")
Set Yield = Workbooks("Sayaka").Sheets("Sheet1").Range("D34")

Set Aresult = ((Reactant / 100) * (1 - Yield)) * 100
Set Bresult = ((Reactant / 100) * (1 - Yield)) * 200
Set Cresult = ((Reactant / 100) * (Yield)) * 300
.......

End Function
JE McGimpsey - 04 Jan 2008 06:41 GMT
First, unless you've defined your own type "Real", you need to use a
built-in type. Numeric values stored in XL cells are always of type
Double, so that's safe to use.

Second, you can't Dim a variable that you've already declared as an
argument in the function's argument list

Third, 'Set' is only used to assign an object variable to an object, for
instance, a range variable to a range as in

  Dim rng As Range
  Set rng = Workbooks("Sayaka").Sheets("Sheet1").Range("D34")

Now the variable rng can be used in place of the range object (in this
case, cell D34 of Sheet1 of workbook Sayaka).

Other (non-object) variables just use the assignment operator (=), so
for instance

  Dim Reactant As Double
  Dim Yield As Double
  Reactant = rng.Value
  Yield = rng.Value

So you might try:

  Public Function Process1( _
           ByVal Reactant As Double, _
           ByVal Yield As Double) As Double
     Dim AResult As Double
     Dim BResult As Double
     Dim CResult As Double

     AResult = (Reactant / (1 - Yield))
     BResult = (Reactant / (1 - Yield)) * 2
     CResult = (Reactant / (1 - Yield)) * 3

     Process1 = AResult + BResult + CResult
  End Function

And call the function from the worksheet as

  =Process1(Sheet1!D34, Sheet1!E34)

In article
<69af3779-3d00-4c20-b980-c5354f3c3f89@s19g2000prg.googlegroups.com>,

> I wonder if some one can tell me what is wrong with my code?
> I am having problems with the first line? I looked online and i
[quoted text clipped - 20 lines]
>
> End Function
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.