Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Simple VBA Module functions do not work on the worksheet!
In both Excel 2000 and 2007 when I enter the following functions on a
worksheet module (or the Excel obect page 'behind' the worksheet), I am unable to execute (or call) on the worksheet. I get the error, [ #NAME? ]. Sub ShowSum() Sum = 1 + 1 MsgBox "The answer is " & Sum End Sub Function CubeRoot() ' returns the cube root of a number CubeRoot = num ^ (1 / 3) End Function |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Simple VBA Module functions do not work on the worksheet!
That is correct. You need to put that code in standard modules.
-- Regards, Juan Pablo González "JCDW" wrote in message ... In both Excel 2000 and 2007 when I enter the following functions on a worksheet module (or the Excel obect page 'behind' the worksheet), I am unable to execute (or call) on the worksheet. I get the error, [ #NAME? ]. Sub ShowSum() Sum = 1 + 1 MsgBox "The answer is " & Sum End Sub Function CubeRoot() ' returns the cube root of a number CubeRoot = num ^ (1 / 3) End Function |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Simple VBA Module functions do not work on the worksheet!
Put them in a standard code module.
And where is Num in the function defined? -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "JCDW" wrote in message ... In both Excel 2000 and 2007 when I enter the following functions on a worksheet module (or the Excel obect page 'behind' the worksheet), I am unable to execute (or call) on the worksheet. I get the error, [ #NAME? ]. Sub ShowSum() Sum = 1 + 1 MsgBox "The answer is " & Sum End Sub Function CubeRoot() ' returns the cube root of a number CubeRoot = num ^ (1 / 3) End Function |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Simple VBA Module functions do not work on the worksheet!
Not worksheet code
use a standard module. ShowSum will work as coded. CubeRoot: Function CubeRoot(num As Double) As Double ' returns the cube root of a number CubeRoot = num ^ (1 / 3) End Function needs an argument -- Gary's Student gsnu200703 "JCDW" wrote: In both Excel 2000 and 2007 when I enter the following functions on a worksheet module (or the Excel obect page 'behind' the worksheet), I am unable to execute (or call) on the worksheet. I get the error, [ #NAME? ]. Sub ShowSum() Sum = 1 + 1 MsgBox "The answer is " & Sum End Sub Function CubeRoot() ' returns the cube root of a number CubeRoot = num ^ (1 / 3) End Function |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Simple VBA Module functions do not work on the worksheet!
While you should probably put your function in a regular code module,
you CAN call it like this (assuming it's in the Sheet1 code module): =Sheet1.Cuberoot(x) Note that I'm assuming you meant Public Function CubeRoot(num As Double) As Double CubeRoot = num ^ (1 / 3) End Function In article , JCDW wrote: In both Excel 2000 and 2007 when I enter the following functions on a worksheet module (or the Excel obect page 'behind' the worksheet), I am unable to execute (or call) on the worksheet. I get the error, [ #NAME? ]. Sub ShowSum() Sum = 1 + 1 MsgBox "The answer is " & Sum End Sub Function CubeRoot() ' returns the cube root of a number CubeRoot = num ^ (1 / 3) End Function |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Simple VBA Module functions do not work on the worksheet!
Obviously I'm a neophyte. What is a 'standard' module? I've been entering
these into VBAProject\MS Excel Objects\Sheet1 (Sheet1) and into VBAProject\Modules\Module1. Not worksheet code use a standard module. ShowSum will work as coded. CubeRoot: Function CubeRoot(num As Double) As Double ' returns the cube root of a number CubeRoot = num ^ (1 / 3) End Function needs an argument -- Gary's Student gsnu200703 "JCDW" wrote: In both Excel 2000 and 2007 when I enter the following functions on a worksheet module (or the Excel obect page 'behind' the worksheet), I am unable to execute (or call) on the worksheet. I get the error, [ #NAME? ]. Sub ShowSum() Sum = 1 + 1 MsgBox "The answer is " & Sum End Sub Function CubeRoot() ' returns the cube root of a number CubeRoot = num ^ (1 / 3) End Function |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Simple VBA Module functions do not work on the worksheet!
What is a 'regular' code module. For that matter, what is an 'irregular'
code module. Yes, I'm just getting started studying VBA, but I sure got hung up in a hurry! And how do I go about rating the responses I've been getting? Sites like this are a gold mine! It's difficult for me to accept that so many people will attempt to help so many who need it! Tks. "JE McGimpsey" wrote: While you should probably put your function in a regular code module, you CAN call it like this (assuming it's in the Sheet1 code module): =Sheet1.Cuberoot(x) Note that I'm assuming you meant Public Function CubeRoot(num As Double) As Double CubeRoot = num ^ (1 / 3) End Function In article , JCDW wrote: In both Excel 2000 and 2007 when I enter the following functions on a worksheet module (or the Excel obect page 'behind' the worksheet), I am unable to execute (or call) on the worksheet. I get the error, [ #NAME? ]. Sub ShowSum() Sum = 1 + 1 MsgBox "The answer is " & Sum End Sub Function CubeRoot() ' returns the cube root of a number CubeRoot = num ^ (1 / 3) End Function |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Simple VBA Module functions do not work on the worksheet!
A "standard", "regular" or "general" module is one that isn't attached to an
Excel object (i.e., not attached to a Form, Worksheet or the Workbook object). These are created either by using the macro recorder or by InsertModule in the vbEditor. I've been entering these into VBAProject\MS Excel Objects\Sheet1 Nope. VBAProject\Modules\Module1. That should do it. There are also Class Modules, but you don't need to worry about those at the moment other than to know you don't need/want to use them for this. HTH, "JCDW" wrote in message ... Obviously I'm a neophyte. What is a 'standard' module? I've been entering these into VBAProject\MS Excel Objects\Sheet1 (Sheet1) and into VBAProject\Modules\Module1. Not worksheet code use a standard module. ShowSum will work as coded. CubeRoot: Function CubeRoot(num As Double) As Double ' returns the cube root of a number CubeRoot = num ^ (1 / 3) End Function needs an argument -- Gary's Student gsnu200703 "JCDW" wrote: In both Excel 2000 and 2007 when I enter the following functions on a worksheet module (or the Excel obect page 'behind' the worksheet), I am unable to execute (or call) on the worksheet. I get the error, [ #NAME? ]. Sub ShowSum() Sum = 1 + 1 MsgBox "The answer is " & Sum End Sub Function CubeRoot() ' returns the cube root of a number CubeRoot = num ^ (1 / 3) End Function |
#9
Posted to microsoft.public.excel.programming
|
|||
|
|||
Simple VBA Module functions do not work on the worksheet!
A regular code module is one that isn't a userform, isn't Thisworkbook, and
isn't a sheet code module. As mentioned before, that is the one from InsertModule menu, the one that you called VBAProject\Modules\Module1 (although it could be Module2, 3, etc. as you add more. As for rating, most of the responses you get are posted on the Usenet newsgroups, so even if you do rate it, it won't show up here. -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "JCDW" wrote in message ... What is a 'regular' code module. For that matter, what is an 'irregular' code module. Yes, I'm just getting started studying VBA, but I sure got hung up in a hurry! And how do I go about rating the responses I've been getting? Sites like this are a gold mine! It's difficult for me to accept that so many people will attempt to help so many who need it! Tks. "JE McGimpsey" wrote: While you should probably put your function in a regular code module, you CAN call it like this (assuming it's in the Sheet1 code module): =Sheet1.Cuberoot(x) Note that I'm assuming you meant Public Function CubeRoot(num As Double) As Double CubeRoot = num ^ (1 / 3) End Function In article , JCDW wrote: In both Excel 2000 and 2007 when I enter the following functions on a worksheet module (or the Excel obect page 'behind' the worksheet), I am unable to execute (or call) on the worksheet. I get the error, [ #NAME? ]. Sub ShowSum() Sum = 1 + 1 MsgBox "The answer is " & Sum End Sub Function CubeRoot() ' returns the cube root of a number CubeRoot = num ^ (1 / 3) End Function |
#10
Posted to microsoft.public.excel.programming
|
|||
|
|||
Simple VBA Module functions do not work on the worksheet!
General/Standard module:
VBAProject\Modules\Module1 the one you get when you do Insert=Module -- Regards, Tom Ogilvy "JCDW" wrote in message ... Obviously I'm a neophyte. What is a 'standard' module? I've been entering these into VBAProject\MS Excel Objects\Sheet1 (Sheet1) and into VBAProject\Modules\Module1. Not worksheet code use a standard module. ShowSum will work as coded. CubeRoot: Function CubeRoot(num As Double) As Double ' returns the cube root of a number CubeRoot = num ^ (1 / 3) End Function needs an argument -- Gary's Student gsnu200703 "JCDW" wrote: In both Excel 2000 and 2007 when I enter the following functions on a worksheet module (or the Excel obect page 'behind' the worksheet), I am unable to execute (or call) on the worksheet. I get the error, [ #NAME? ]. Sub ShowSum() Sum = 1 + 1 MsgBox "The answer is " & Sum End Sub Function CubeRoot() ' returns the cube root of a number CubeRoot = num ^ (1 / 3) End Function |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How does a module of VB work in a Worksheet? | Excel Worksheet Functions | |||
CLASS MODULE & SIMPLE MODULE | Excel Discussion (Misc queries) | |||
Calling worksheet functions from within a module | Excel Programming | |||
Calling worksheet module from other module. | Excel Programming | |||
Run worksheet module code from workbook module? | Excel Programming |