Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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
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
How does a module of VB work in a Worksheet? VJ Sharma[_2_] Excel Worksheet Functions 1 April 30th 09 04:15 PM
CLASS MODULE & SIMPLE MODULE FARAZ QURESHI Excel Discussion (Misc queries) 1 September 7th 07 09:32 AM
Calling worksheet functions from within a module Daz Excel Programming 1 November 29th 06 03:05 AM
Calling worksheet module from other module. Michael Malinsky Excel Programming 2 December 14th 05 08:47 PM
Run worksheet module code from workbook module? keithb Excel Programming 1 August 14th 05 04:04 AM


All times are GMT +1. The time now is 09:44 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"