![]() |
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 |
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/ |
All times are GMT +1. The time now is 01:50 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com