Pass Value From Function To Procedure
Aug 11, 2006
If I have code like this
Private Sub cmdHex_Click()
Dim HexNum As String
HexNum = Me.txtHexVal
'Call a function
ToBinary (HexNum)
'Now do something else
End Sub
And the function ToBinary creates a value called BinVal. How do I pass it back to my subprocedure to do something with it.
View 4 Replies
ADVERTISEMENT
Dec 11, 2006
I want to be able to call a procedure and pas 2 variables that it will need to it.
The code looks like this:
Private Sub UpdateScreen(StartLine As Byte, EndLine As Byte)
End Sub
UpdateScreen(104 , 140)
For some odd reason I get an "Expected: = "error when I enter the last line. I works if I send only one variable, but not when I send 2.
View 2 Replies
View Related
Feb 15, 2010
I have a userform that has a number of cascading comboboxes, however i wish to use the same cascading feature in a number of other userforms. So what i am trying to achive is calling the cascading element from a public macro, to do this i need to pass the userform name to the procedure. The snippet of code i am using is:
Form:
Private Sub ComboBox1_Change()
If ComboBox1.Value <> "" Then
myform = Me.Name
Call Cascade1(myform)
End If
End Sub
Module:
ub Cascade1(myform)
myform.Label2.Visible = True
myform.ComboBox2.Visible = True
myform.ComboBox2.RowSource = Range(myform.ComboBox1.RowSource).Cells(myform. ComboBox1.ListIndex + 1, 1)
End Sub
View 2 Replies
View Related
Sep 10, 2007
I have a procedure that I want to pass two arrays to. When I pass a single array it works fine but as soon as I try to pass two arrays I get a syntax error. Both arrays are declared exactly the same way and are used in the same way. Am I limited to passing only one array per procedure?
View 8 Replies
View Related
Jan 1, 2008
I want to put some colour in the cells B2, B3, B4, B5, etc and a put black the edge of every box. For do that i make a subrutime that put some color in the range that i want (only if i write "B2" or "B2:B5"), but if i want to put a black edge in all the box i can't do "B2:B5". Then i tried to do something like:
For i=2 To 5 Step 1
Call Boxcute(ActiveSheet.Cells(i,2))
Next i
Sub Boxcute (Box As String)
Range(Box).Selection
etc.
End Sub
But Excel gives me a error with Box and Range.
View 2 Replies
View Related
Apr 27, 2007
Is it possible to call a stored proc from excel and pass through a paramter?
If it is would anyone have a clue how to do this?
View 11 Replies
View Related
May 31, 2013
I need to pass range information (eg. WorkSheets("abc").Range("A1") as text or ??) from a cell (ie the above text is in a cell on some worksheet, say "XYZ") to a VBA procedure or could directly use it in the procedure, similar to...
Sub MyProc(RngInfo as string [or?])
dim RRng as range
Set RRng= RngInfo ??? it is this part I'm really not sure how to do
where RngInfo is a worksheet that has a "named" cell that contains the above cell with the indicated range in it.
eg. RngInfo is worksheets("XYZ").Range("D1") where D1 contains the text (or ?)WorkSheets("abc").Range("A1")
I've only indicated these as text items because I'm not sure what/how you would do this. The end purpose of this is to pass variable Range information from a cell on a WS either into (or use within directly) a VBA Sub. I guess I could pass the WS and Range Address as a single string separated by a "Char" and use Split to separate them and then recombine using Worksheets(Parm(0)).Range(Parm(1)) but it seems like it should be easier than that.
View 9 Replies
View Related
Mar 22, 2007
Have a spreadsheet for creating employee schedules (any number of employees, 3 rows per employee, 5 columns for each day). I want to move all employees' info for one day (5 columns and XX rows) to another area and then clear the employees' data for that day. I have the code working for Monday but I don't want to duplicate it 6 more times for Tue -Sun. I have set up named ranges (i.e. MonFT, TueFT, etc.
I would like to call one subprocedure to do this and pass parameters for each day so the ranges can be changed to reflect the desired day?
I am doing this for holidays; i.e. if there is a Wed. holiday, store all of Wednesday's data and clear Wed. Then restore all Wed data when preparing the schedule for the following week.
View 7 Replies
View Related
Feb 2, 2010
I need to extract the filename “My Excel File” from Worksheets(“Sheet1”).Range(“A1”), whose value = C:Documents and Settingsuser1DesktopMy Excel File
I found on Chip Pearson’s site a Function TrimToChar which, using SearchFromRight and a TrimChar of “” will trim OFF the filename “My Excel File”, leaving the Path.
But, I think I could use his function to tell me the number of characters in the Path and then use that to extract the remaining characters from the total character length (Mid Function)
Problem is, I don’t have a clue how to call a Function in VBA to work on Worksheets(“Sheet1”).Range(“A1”). How do you set the InputText , TrimChar, & SearchFromRight?????
(eventually, this will be in a loop, where I extract the filename from a Dynamic Named Range (list) in Column A)
View 3 Replies
View Related
Mar 2, 2012
I have found some code that does what I want- but i do not understand how to use - call it. The programmer says ...
GetNetworkIPAddress()
' can be called from a worksheet cell using the formula:
' =GetNetworkIPAddress()
I have put this in a cell but i ger an error #Name?
what should i do ?
View 9 Replies
View Related
Jun 25, 2013
When I step-through my code below, it always opens the first file in the directory "C:Pyramid Files", but when it comes back to the Pyramid Files sub after fully processing the first file via various other subs, the VB Editor apparently doesn't like something about this line: StrFile = Dir(), since it quits after "snapping-back" to the previous sub Initialize(). I have also tried StrFile = Dir, but that doesn't work either. I did Dim Strfile in the General Declarations. When I set Watches for Dir and Dir(), I get the value "Invalid procedure call or argument" for both, as if the directory function lost the value. I can't determine why this is happening.
VB:
Dim WSM As Worksheet, WSB As Worksheet, WS1 As Worksheet, [U]StrFile As String[/U], StrDirectory As String, ClientCode As String
Dim Filename As String, LastRowb As Long, LastColB As Integer, LastRow1 As Integer, NextRowC As Integer, x As Integer, y As Integer
[Code] .......
View 4 Replies
View Related
Aug 30, 2012
This error message in line vpp:
Invalid procedure call or argument
Code:
Function fn1(ByVal a, ByVal i, ByVal e, ByVal N, ByVal w, ByVal ta)
Pi = Application.WorksheetFunction.Pi
mhu = 398600
vpp = (mhu / Math.Sqr(mhu * a * (1 - e ^ 2))) * (-Math.Sin(ta * Pi / 180))
fn1 = 2 * vpp
End Function
View 9 Replies
View Related
Jun 11, 2009
I am attempting to call a Function from a cell and pass it a range and an Integer. The Integer works fine, but I cannot get the Range to pass into the function correctly.
View 8 Replies
View Related
Oct 11, 2006
I have a simple/dumb question... How do you "capture" a value that is returned by a custom function.
I have tried searching the forums for this & I know that I should by all rights know how to do this by now... but I just can't figure it out.
Here is a Function that I copied from Ktrasler in this thread:
Week Numbers
Public Function MyWeek(DateArg As Date) As Byte
Const BaseDate = "30/12/2001"
DateArg = CDate(DateArg) - (Weekday(DateArg) - 1)
MyWeek = Int(((DateArg - CDate(BaseDate)) / 7) Mod 52)
If MyWeek = 0 Then MyWeek = 52
End Function
I know how to pass variables to Functions, and tried this one out & it worked splendidly for my needs, but how do I take the value of "MyWeek" and use it in the subroutine that I am calling it from?
View 3 Replies
View Related
Mar 10, 2008
I have a simple function defined in one of my worksheets (Sheet1):
Function AddFuel(fuel As String)
MsgBox fuel
End Function
How would I be able to call this from a form button event?
Private Sub CommandButton1_Click()
Sheet1.AddFuel(TextBox1)
End Sub
Everytime I try running this code I receive the error: Run-time error '1004'; Application-defined or, Object-defined error. I've even tried Application.Run("Sheet1.AddFuel", TextBox1) but still no luck. I think this is a pretty common question but I couldn't find any answer to it on the forums.
View 2 Replies
View Related
Aug 8, 2014
I have a VBA shell script that worked just fine on another computer, but now it won't run.
The code that won't execute is:
[Code] ........
View 12 Replies
View Related
Nov 15, 2013
I understand that the SumProduct doesn't have the same capabilities in VBA as it does in worksheet formulas. I am trying to construct it in an evaluate statement in VBA but the problem is I am using it in a userform, so the conditionals are passed from two combo boxes. Here is the worksheet formula
Code:
=SUMPRODUCT((Table1[Home]=C3)*(Table1[Away]=M3)*(Table1[Goals (H)]>Table1[Goals (A)]))
The values C3 and M3 refer to a cell known as "Home" & "Away". It's comparing to the two teams selected to a table with game stats to show wins and losses. The user form has a combo box list with those teams. Combo Box 1 passes to a variable known as hTeam and Combo Box 2 passes to a variable known as aTeam. I need those values passed through to C3 and M3. Here's what I constructed but get a type mismatch
Code:
Evaluate("=SUMPRODUCT((Table1[Home]=" & chr(34) & hTeam & chr(34) & ")*(Table1[Away]
=" & chr(34) & aTeam & chr(34) & ")*(Table1[Goals(H)]>Table1[Goals(A)]))")
View 4 Replies
View Related
Feb 5, 2014
Basically someone has coded a VBA script to pull a users details from AD when a button is clicked, using the staff id as the search criteria.
I've amended the criteria so it uses Environ$(USERNAME) to find details of the current logged on user, but i am struggling to get the resulting information out of the Sub to be used in other Subs! It currently just fills a cell with the required info.
View 1 Replies
View Related
Dec 28, 2006
I am trying to write a User Defined Function in VBA to perform a simple two-dimensional table lookup. I have the temperature distribution in a solid given in a table in Sheet2. The first column of the table contains the time values, the first row contains the spacial values (radii), and the intersections contain temperature values. These ranges are named times, radii, and temperatures. In Excel, I can perform the lookup using: =index(temperatures, match(time, times, 1), match(radius, radii, 1))
But how do you do this in VBA? More specifically, how do you deal with passing ranges to the WorksheetFunctions?
Function temperature_ref(time_range As Range, radii_range As Range, temperatures_range As Range, time As Double, raduis As Double)
r = WorksheetFunction.Match(time, time_range, 1)
c = WorksheetFunction.Match(radius, radii_range, 1)
temperature = WorksheetFunction.Index(temperatures_range, r, c)
End Function
This function would be called (from any worksheet) as..................
View 4 Replies
View Related
Mar 3, 2008
I'm trying to do is pass the contents of a listbox to a function to sort it into alphabeticalorder. I get a error saying object required
Sub PopulateAll()
Dim lgLastRow As Long
Dim lgRowCounter As Long
Dim intCounter As Integer
Dim olb As MSForms.ListBox
For intCounter = 0 To UBound(vAllEnv)
Me.lstAll.AddItem (vAllEnv(intCounter))
Next intCounter
Set olb = frmOptions.lstAll.........................
View 9 Replies
View Related
Jan 14, 2010
I have 5 worksheets each with tables that are formatted the same on each sheet. I have named each table as a named range (ex:filter5tsd15BSF). I have a userdefined function that interpolates values for a single table in a vba module. I can make this function work for a single table by calling the function as =Linterp(filter5tsd15BSF,C12) so I know the function is OK. However, I really rather program this some way that all the tables get passed to the function and then a select case for the conditions for which filter and which TSD (15 or 25) will then select the correct table.
View 2 Replies
View Related
Dec 23, 2009
I am trying to call a function that calculates forecast error (wMAPE). This function needs to be able to handle passing in non-contiguous ranges. I can't seem to figure out how to do that.
Function wMAPE(Forecasts As Range, Actuals As Range, Weights As Range) As Variant
Dim Denominator As Double
Dim Numerator As Double
Dim i As Long
Dim Fcst As Variant
Dim Act As Variant
Dim Wt As Variant
If Forecasts.Cells.Count Actuals.Cells.Count Then MsgBox ("Error: Arrays not same size")
If Forecasts.Cells.Count Weights.Cells.Count Then MsgBox ("Error: Arrays not same size")
Denominator = 0............
View 9 Replies
View Related
Jul 28, 2006
I recorded a function and got the message box "Invalid Outside Procedure" when I tried to run the macro. I don't understand what it means or how to prevent it.
View 2 Replies
View Related
Apr 21, 2009
I have the following codes used with a user form, but they are all not working due to an outside procedure problem,
View 14 Replies
View Related
Dec 11, 2007
I've created a macro with a custom dialog box, but I don't know how to make the transition from when I make the dialog box pop up, the user enters the information, then they click "Continue" or "Cancel" or whatever it may be, how to do I make it happen from there out?
Do I make the command buttons a boolean and if they click it's true? How do I make it work?
View 14 Replies
View Related
Sep 6, 2007
I need in column E the value "complete" but only against the last row of each system from column B, if column D ="draft del" and is not null. For example system V0523 is draft del and so is complete, therefore I would like "complete" in column E row 10.
******** ******************** ************************************************************************>Microsoft Excel - CA_ TDM_ ACQD_TBLDATAMODULE(LEFT JOIN)_all_systems.xls___Running: 11.0 : OS = Windows XP (F)ile (E)dit (V)iew (I)nsert (O)ptions (T)ools (D)ata (W)indow (H)elp (A)boutB2B3B4B5B6B7B8B9B10B11B12B13B14B15B16B17=
ABCDE1EIACODXA*LSACONXBDM_MGT_STATUSDM_QA_STATUS12EH101-VH71V00V00**3EH101-VH71V00V00**4EH101-VH71V00V00**5EH101-VH71V01V01WIP*6EH101-VH71V01V01WIP*7EH101-VH71V01V01WIP*8EH101-VH71V0523V0523001DRAFT*DEL*9EH101-VH71V0523V0523001DRAFT*DEL*10EH101-VH71V0523V0523001DRAFT*DEL*11EH101-VH71V0552V0552001**12EH101-VH71V0552V0552003**13EH101-VH71V0552V0552005**14EH101-VH71V0552V0552007**15EH101-VH71V0552V0552009**16EH101-VH71V0552V0552011**17EH101-VH71V0552V0552013**CA, TDM, ACQD_TBLDATAMODULE(LEF*
[HtmlMaker 2.42] To see the formula in the cells just click on the cells hyperlink or click the Name box
PLEASE DO NOT QUOTE THIS TABLE IMAGE ON SAME PAGE! OTHEWISE, ERROR OF JavaScript OCCUR.
View 9 Replies
View Related
Sep 2, 2009
I have the following macros,but want them to run in sequence but i don't know how.
I plus won't another macro to save the archive as .txt
1. I use the following macro to open .txts so the cells go where i want to
Sub NewTextImport()
myfile = Application. GetOpenFilename("Text Files,*.txt")
Workbooks.OpenText Filename:=myfile _
, Origin:=1253, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:= Array( _
Array(0, 2), Array(17, 2), Array(34, 2), Array(56, 2), Array(102, 1)), _
TrailingMinusNumbers:=True
Columns("A:A").EntireColumn.AutoFit
Columns("B:B").EntireColumn.AutoFit
Columns("C:C").EntireColumn.AutoFit
Columns("D:D").EntireColumn.AutoFit
End Sub
2.Remove the unwanted zeros from Column E.............
View 2 Replies
View Related
Jun 19, 2007
I have written a macro in Excel VBA. The code is divided into modules and each module is having various procedures. I'm trying to run a procedure written in modules2 from module1. I'm getting an error message "Expected Variable or Procedure, not module".
View 2 Replies
View Related
Nov 27, 2007
I have a userform in an add-in (which is loaded), when I try and call it from an excel sheet, I get the following error "Variable not defined"
Private Sub CommandButton3_Click()
UserForm1.Show
End Sub
The code in the userform is all private subs.
Similarly when calling a public sub from the add-in such as;
Private Sub CommandButton3_Click()
Call SillySub
End Sub
I get the error "Sub or Function not defined".
How should I be doing this?
View 3 Replies
View Related
Jun 19, 2008
how do you call another sub's function from another sub? For example:
Sub Worksheet_SelectionChange(ByVal Target As Range)
StartingDate:
Static STempHolding As String
If STempHolding <> "" Then OldStartingDate = STempHolding
STempHolding = Target.Value
EndingDate:
Static ETempHolding As String
If ETempHolding <> "" Then OldEndingDate = ETempHolding
ETempHolding = Target.Value
End Sub
If i just wanted to call the StartingDate function, from my Worksheet_Change sub how would i do that?
View 5 Replies
View Related