Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Function Calling Subroutine

I am new to VB coding and trying to develop a few tools to make lif
easier for myself. Currently, I am trying to insert values in a table
user-inputs fields for results. After the inputs, I want to look up
results according to age. For a test run I am trying some coding in
simple form, as shown below:

Function TestRun(AnyNo As Integer)
Call TRun(AnyNo)
TestRun = Range("A7")
End Function

Sub TRun(AnyNo)
Range("A7") = AnyNo
End Sub

This works when I run it in the Immidiate Window but not on th
worksheet. Is there a certain setup in excel that I need checke
before this method can work? If no, are there altervatives for such a
method to work? Thanks

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Function Calling Subroutine

Hi
the problem is that functions are not allowed to change any cells /
formats / etc. They can only return values. But in your code you're
calling a sub which changes a cell. This is not allowed. Therefor the
code
Function TestRun(AnyNo As Integer)
TestRun = Range("A7").value *AnyNo
End Function

would work
--
Regards
Frank Kabel
Frankfurt, Germany

I am new to VB coding and trying to develop a few tools to make life
easier for myself. Currently, I am trying to insert values in a
tables user-inputs fields for results. After the inputs, I want to
look up results according to age. For a test run I am trying some
coding in a simple form, as shown below:

Function TestRun(AnyNo As Integer)
Call TRun(AnyNo)
TestRun = Range("A7")
End Function

Sub TRun(AnyNo)
Range("A7") = AnyNo
End Sub

This works when I run it in the Immidiate Window but not on the
worksheet. Is there a certain setup in excel that I need checked
before this method can work? If no, are there altervatives for such

a
method to work? Thanks.


---
Message posted from http://www.ExcelForum.com/


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
Call a subroutine using variable subroutine name dhstein Excel Discussion (Misc queries) 3 July 26th 09 08:28 PM
Calling a function in my SQL-DB from VBA KSor Excel Discussion (Misc queries) 0 March 11th 09 02:08 PM
calling a new function Excel gives me #NAME? Mark Dvorkin Excel Worksheet Functions 4 July 10th 05 01:29 AM
how to make a link to a function or subroutine... Pablo Chemes Excel Programming 2 December 4th 03 06:38 PM
Calling the Solver via a subroutine James[_8_] Excel Programming 1 July 10th 03 01:08 AM


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