Can A Subroutine Be Called Within A Function

May 12, 2006

1. Can a Subroutine be called from within a user-defined Public Function? How?

2. Is there a difference between calling a subroutine with a 'Call Sub_Name' statement, vs. calling the subroutine with an 'Application.Run'(?? or similar) statement?

View 5 Replies


ADVERTISEMENT

Passing Variables Back From A Called Subroutine?

Nov 3, 2009

I have a question. Can this be done. Pass a couple of varibles back from a called sub routine?

The calling sub calls the called sub does which has code plus a couple of varibles needing to come back.

Scope: The called sub is a series of case statements with code and sets varibles which are needed back in the calling sub.

View 6 Replies View Related

Import Variable From Another Function Into Subroutine?

Jan 19, 2014

In these lines of code I am adding hyperlinks to cells in a row. It shows my steps recorded but since there are some 4,000 cells I need a macro to do it automagically. The target cells are in sequential worksheets but in each case follow the sane pattern (i.e. P2, H3, X3, D4, etc.). Could I capture this routine for each sheet by the sub for each? If so how?

Range("B2").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, address:="", SubAddress:= _
"'Max tree base'!P2", TextToDisplay:="'Max tree base'!P2"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, address:="", SubAddress:= _
"'Max tree base'!H3", TextToDisplay:="'Max tree base'!H3"

[Code] ...........

View 1 Replies View Related

Function Being Called At Inappropriate Time

May 29, 2009

Function being called at inappropriate time
I have the following code in the active worksheet:

View 4 Replies View Related

Series Of Subs Called From Function

Apr 15, 2013

I have a series of procedures I am calling from a function that each run fine when executed individually. These procedure are titled: DataValidation, Test1, Test2

The function will not run past Test2- I do not get the msgbox "Stage 2"

Code:
Public ArrayD
Public ArrayD2 As Variant
Public RngD3 As Range

Public Function Test(arg2 As Range)

DataValidation arg2

[Code] ............

View 4 Replies View Related

Debug Function Called From Another File

Jun 26, 2007

I have a macro that calls functions from another workbook.

For example:

Private Sub Worksheet_Change(ByVal target As Range)
If ThisWorkbook.OpenCommon <> -1 Then _
Application.Run Workbooks("common.xls").name & "!Arkusz1.CellChange", target
End Sub

But when I get an error in CellChange function from "common.xls" workbook, debugger points only to the third line of the code above, not to the bad line in called function.
Is there any way to change this behaviour (maybe some tool etc.)?

View 5 Replies View Related

Preventing A Function Being Called If Argument Is Unchanged

Jun 27, 2006

I have a function in a cell triggered on the value returned by a DDE link in another cell.

e.g. cell A1 contains =function1(A2) and cell A2 contains
=ADVFN|NYSE_CAT!CUR

function1 is triggered each time the DDE link updates regardless of whether the result returned has changed or not. How do I prevent function1 being triggered if the returned value has not changed?

View 9 Replies View Related

Analyzer That Lotus 123 Had With It's Function Called Backsolver

Feb 24, 2008

I'm trying to replicate the same functionality using Excel Analyzer that Lotus 123 had with it's function called Backsolver.

Below is a simple matirx of expenses, that shows a sum total of 3297. I want to change the number 3297 to 5000 and I want the rows and columns to add up to that total based on the same % relationship that existed when this matrix added to 3297

This technique is useful when you are trying to spread changes in a plan and you need to develop placeholders that add up and accross to the new target i.e, 5000 based on the previous targets % relationships that existed when the row and columns added up to 3297

I can use the analyzer, but when it finds its solution it returns negative values as part of the solution. I'm missing something in trying to set the parameters so that it won't return me negative #'s.

View 9 Replies View Related

To Create A Function Macro Called FSTD

Nov 5, 2008

i need to create a function macro Called FSTD that inserts words into a cell and conditionally formats them depending on th number in the cell on the left.

in the sheet there are ranges that the number will fall between.

Example

Cell B1 is the cell were i want to run the function in
Cell A1 is the cell with the number that is used in the function

Cells A3:A7 are that ranges that i need to use in the function

E.g. if the number in A1 is less than A6 = i want "P" to appear in the cell with a red backround

if the number is greater than A6 but less than A5 = i want "M" to apear with an orange back round

if the number is Greater than A5 but less than A4 = i want "E" to apear with a green backround

even if it is possible to do without changing the backrounds, just to insert the letters

View 9 Replies View Related

UDF Working When Called From Sub, Doesn't Work As Worksheet Function

Mar 28, 2009

I have written a user-defined function that searches for a small range within a larger range. The function requires two input parameters: the range you are looking for, and the range you want to look within.

For example, I might look for the string of values in cells A1:D1 in a larger range E1:H20. The function returns the row number in the larger range where the smaller range is found.

My problem is this: The function is working fine when I call it from another sub procedure. However, when I try to run it as a worksheet function, I get a "#VALUE!" error. The function pops up in the "insert function" menu, and it prompts for the two input parameters.

View 6 Replies View Related

Excel 3003 :: How To Prevent To Stop Macro Called From A Function

May 3, 2014

I am trying to use the simplest code possible (being a novice) to execute a macro which makes a copy of Cell A1:A4 and paste its values to Cells B1:B4 if cell B5=1 (or whatever). The Macro with copy and paste works (I recorded it and in my testing it was ok). And also the function, that contains If-Then status of cell B5, works and calls correctly the Macro.

Yet when the macro is called by the function (=CopyMyCells(B5)), the Macro (MacroCopy) runs - I tested this with a Msgbox - but stops just in doing what I need, i.e. in doing the copy-paste process. Here the code which is placed in a module of the proper Worksheet (Excel 2003, on WinXPSp3):

[Code] ........

View 6 Replies View Related

"PC" To Show Up If I Type A Sentence Containing "Called Parent", "Called Dad", Or "Called Mon"

Dec 2, 2009

I need "PC" to show up if I type a sentence containing "Called Parent", "Called Dad", or "Called Mon". Here is what I'm trying.

View 2 Replies View Related

UDF: How To "get To" The Cell That The Function Is Being Called From (NOT Activecell)

Aug 5, 2008

Suppose I have this UDF:

Public Function test()

test = ActiveCell.Column

End Function

This is great only when I evaluate the function test() one cell at a time. When I copy this formula to other cells or perform autofill Excel thinks that the active cell is the first cell in the series.

What I really want is for the function to return the column of the CELL that contains the function, and not the cell that's last clicked.

View 9 Replies View Related

VBA Does Not Run Through All Of Code In Subroutine

Dec 14, 2013

VBA jumps out of my called subroutine which is stored in a Module halfway.

When I call the SortLec() sub, it runs until y1 = Application.Match(MC & "-" & CI, rng, 0), and then it just jumps back to the SUB commandbutton1_click() IF statement. Why is it that VBA skips the rest of the code from my sub?

Option Explicit

Private Sub CommandButton1_Click()
Dim i As Integer
Dim numofrows As Integer
Dim workbook_directory As String
Dim file_name1 As String

[Code] ............

View 2 Replies View Related

VBA Calling Another Subroutine

Mar 14, 2008

Im trying to call another subroutine within the same workbook but it doesnt work,

---------------------

Sub Macro1()

Dim mac1 As Variant
Dim mysub As Variant

Select Case Cells(1, 3)
Case mac1
Call mysub

End Select

End Sub
---------------------

View 9 Replies View Related

Writing Subroutine

Oct 27, 2008

in writing a subroutine that needs to ask the user

1) tax file number
2) Income
3) tax withheld

It then needs to use a function that i already made called 'incometax' that calculates 'taxpayable' and use that to calculate taxreturn (difference between 'taxpayable' and 'taxwithheld').

I then need it to output like this in a message box

Estimate for tax file number: .....
Created on ......
Total income: ......
Tax witheld: .......
Tax payable: ......Tax return: .......

View 9 Replies View Related

Calling A Subroutine

May 23, 2007

Is calling a subroutine within another different than running it from the play button in the VB editor? I am getting different results.

I have the following code that I want to call from another subroutine that creates a series of command buttons.

Sub DynamicButtons()
Dim ButtonCount As Integer
Dim ctl As OLEObject

' Create the Button objects
ButtonCount = 0
For Each ctl In Sheets("Sheet1").OLEObjects .............

View 9 Replies View Related

How To Refer To Object Which Is In Another Subroutine

Apr 3, 2014

Is it possible to refer to an object which is in another subroutine?

Or should i have to give its definition in each sub i need it?

View 7 Replies View Related

How To Allocate Subroutine To New Button

Feb 26, 2014

I need to allocate an existing subroutine (its code below) to a new button I'd like to add to my sheet. Two questions arise: to use "form control" or "activeX"?, also should I redfine the first line of the code?

[Code] .........

View 4 Replies View Related

Passing Subroutine As A Parameter

Mar 26, 2009

I want to pass the name of the routine as a parameter.

View 6 Replies View Related

Passing Variables To Subroutine

Feb 20, 2010

My code passes a string created by a function to procedure. It all works great, but i need to add something so that if the string = false then sub doesn't run. What's the best way to do that. Here is some of the

View 6 Replies View Related

424 Error When Calling Into Subroutine?

Nov 17, 2013

I met problem in calling into a subroutine. It is error 424. I have dim all variable. However I still get it.

Code:
Sub UpdateAll()
'
' UpdateAll Macro

[Code]....

I got the error when I pressed F8 to step into the getOneRecord() function, which is highlighted in red.

View 2 Replies View Related

Passing A Variable To A Subroutine

Dec 23, 2007

My code defines a variable: newrow. Then I call a subroutine using the Call command.
The subroutine does not recognize newrow.

It says it has value zero. How can I pass the value of newrow on to the subroutine.

View 9 Replies View Related

Executing The Same Subroutine For All Checkboxes

Mar 6, 2008

I have 60 checkboxes on my spreadsheet and basically, when any of the checkboxes are clicked on, the same action should be performed.

The only way I know how to do this is if I were to write the same code 60 times... one for each checkbox_click() method.

View 9 Replies View Related

Subroutine To Delete A Row In Another Worksheet Not Work?

Aug 1, 2014

I have a short subroutine to delete a row in a second worksheet (SUMMARY EXPENSES) if one is deleted in the main worksheet (AS CODES) as per below:

[Code] .......

In theory the row deletion should only be triggered IF dynamiccounter is smaller than staticcounter, but the fact is anything whatsoever triggers the row deletion. If I type text into a cell a row gets deleted. If I copy a cell, a row gets deleted. It works great at deleting the line, but I suspect it has nothing to do with the counters I set up and the reassigning of the counter value towards the end of the If statement.

View 4 Replies View Related

Slight Modification To Formatting Subroutine

Nov 7, 2013

I have a small sub routine below I would like to make a slight modification to. The routine currently references formatting relative to the Offset statement in bold below. Instead, I would like the formatting to come from a cell address listed in a cell just to the left of the cursor when the statement is encountered.

View 2 Replies View Related

Call A Subroutine From An Xls File On The Network

Sep 30, 2008

I'm trying to put some visual basic out on the network drive at work so I created a book and called it Macro.xls. I then saved the code within that book and saved it out on my network. I'm now trying to run that code by calling the sub and don't know how to do that.

View 7 Replies View Related

Keyword Call When Invoking A Subroutine

Nov 18, 2009

Am I right to say that "Call" is not mandatory and should be used only to invoke subroutines that do not return a value?

If you use the keyword "Call" to invoke a subroutine that does return something, the returned variable will be discarded.

View 10 Replies View Related

Reference Controller That Trigger Subroutine?

Nov 22, 2011

Is there a way to reference the controller that triggered a subroutine??

like the ME or ThisWorkbook, but for controllers on userforms.

View 2 Replies View Related

Subroutine To Delete Non-header Rows

Dec 28, 2011

I have a subroutine to delete non-header rows. This sub routine seems to choke on the delete line.

Code:
Sub CleanSheets(Header As Integer, WorkSheetToClean As Worksheet)

Dim WorkSheetRows As Integer

WorkSheetRows = WorkSheetToClean.Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlFormulas).Row
WorkSheetToClean.Rows(Header, WorkSheetRows).EntireRow.Delete

End Sub

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved