Re: Running a Sub from a cell expression in Excel



On 15 דצמבר, 22:59, Steve Rindsberg <ab...@xxxxxxxxxxxxx> wrote:
In article <84f316e3-fd70-4398-9277-ca5041ac0...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,

David K. wrote:
I am new to VBA. I wrote a simple Sub in VBA (say MySub). When I try
to run it from a cell expression in Excel (=MySub), I get the
following message:  "That name is not valid".
Any help will be appreciated.

I think you need a function rather than a sub (sub doesn't return a value, a
function does)

Example:  this in a cell:

=GimmeFive()

Invokes this:

Function GimmeFive() As Integer
    GimmeFive = 5
End Function

I'm a PowerPointPusher.  There's probably lots more to this I haven't a clue
about, but this might be enough to get you going.

--
Steve Rindsberg, PPT MVP
PPT FAQ:  www.pptfaq.com
PPTools:  www.pptools.com
================================================

Steve,

Thank you for your help.
Yes, I know that a function returns a value. Yet, Sub is what I need,
since it performs some procedure. for example: Say my Sub displays
some message.
My question still stands; How do I run a Sub from within an Excel
cell.

David
.



Relevant Pages

  • Re: Passing excel objects to subroutines as parameters
    ... finds a specified cell value on an excel spreadsheet and then ... formats the found cell and inserts text next to the found cell. ... statement the code simply exits the sub routine and proceeds with ... What I go by when automating, I can play with the stuff in the ...
    (microsoft.public.access.modulesdaovba)
  • Re: Passing excel objects to subroutines as parameters
    ... finds a specified cell value on an excel spreadsheet and then formats ... the found cell and inserts text next to the found cell. ... The sub is ... Set rng = Ws.Range'.Address ...
    (microsoft.public.access.modulesdaovba)
  • Re: SendKeys "(^ {HOME})"
    ... I've tried the following combos of VBA and Excel 2000 v9.0.2720 Application. ... right Cell being the only Cell in the lower, ... Public Sub SelectLoRtPaneUpLfCell() ... Dim lUpLfPaneMaxColNum As Long ...
    (microsoft.public.excel.programming)
  • Re: Passing excel objects to subroutines as parameters
    ... finds a specified cell value on an excel spreadsheet and then formats ... the found cell and inserts text next to the found cell. ... The sub is ... Dim xlApp As Excel.Application ...
    (microsoft.public.access.modulesdaovba)
  • Re: how to change a cell content in a visual basic function?
    ... Private Sub Worksheet_Change ... It looks to see if you changed A1, if it's some other cell, it gets out. ... Then it continues through the error handler and tells excel to start looking for ... Rightclick on the worksheet tab that should have this behavior. ...
    (microsoft.public.excel)

Loading