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


ADVERTISEMENT

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

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

Invalid Use Of Property When Calling Subroutine

Jun 4, 2009

I've ran into a problem with one of my workbooks which appears to only affect Excel 2007. It works fine in Excel 2003.

Basically I am calling a sub routine contained in a module from worksheet code. The sub is Public in the module and I use the following code to call the sub.. The code Errors immediately here -

Private Sub mybutton_Click()
Worksheet Code -

Private Sub mybutton_Click()
mysub
End Sub
Module Code -

Public Sub mysub()
...my code
End Sub

This works fine in Excel 2003?! Is there a different way to call the sub with Excel 2007

View 9 Replies View Related

Error On Button Code Reference To A Subroutine

Mar 2, 2007

I'm having trouble calling a subroutine from a command button. It's puzzling because I've set up buttons before and didn't have this trouble.

Here is my button
Private Sub EPConversionButton1_Click(ByVal target As Range)
Convert_Hrs_EP target
End Sub
And here is the subroutine.

Sub Convert_Hrs_EP(target As Range)
End Sub
There's nothing there yet, but I keep getting error messages regarding the transfer from the button code to the subroutine.

The message is: Procedure declaration does not match description of event or procedure having the same name. The Help file says this means that my procedure has the same name as an event, but does not have the same signature. But it's not so.

View 9 Replies View Related

Dynamic Subroutine Generation Creates Compile Error

Oct 4, 2007

I'm am running Excel 2003 SP2 on Windows XP SP2.

I have a macro which modifies cells in a spreadsheet. But for brevity sake, I have an empty spreadsheet which has an Auto_open macro and two subroutines in it. The subroutines initially consist of just the Sub and End Sub statements.

The Auto_open procedure reads in lines from two text files (generated by another application), and inserts the lines into each of the empty subroutines. Auto_open then runs the two subroutines.

I have been able to get this dynamic creation of the subroutines to work for one subroutine, but not for the second. I receive the compile error: "Only comments may appear after End Sub, End Function, or End Property". I don't see anything wrong with the inserted code.

The modified subroutines appear fine, and if I save the macros with the modified code, close excel, rename the text files so they are no longer read in, and re-open the spreadsheet, the auto_open procedure and the two subroutines run fine. This tells me the code itself is okay, and yet it won't work during the initial run.

Below is the macro code in its original state:

Sub Auto_open()
Dim fso, f
Dim VBCodeMod As Object
Dim LineNum As Long
Dim StrFileName As String

ShowVisualBasicEditor = True

Set VBCodeMod = ThisWorkbook.VBProject.VBComponents("Module1").CodeModule

End Sub
----------------------
The contents of the read in file, %TEMP%subA.txt, is just one line:
MsgBox("inside SubA")

The contents of the read in file, %TEMP%subB.txt, is just one line:
MsgBox("inside SubB")

------------------------
When I open the spreadsheet the first time, it gives me the first message box from Sub A, but then generates the error and highlights the Sub SubB() line.

To duplicate the problem:
1. Insert the macro into a spreadsheet. Save and exit it.

2. Create the files %TEMP%subA.txt and %TEMP%subB.txt containing the single MsgBox lines.

3. Open up the spreadsheet. SubA will run and a message box will appear. Then the compilation error will occur.

4. Save and exit the spreadsheet.

SubA will now contain:

Sub SubA()
MsgBox("inside SubA")

End Sub

SubB will now contain:
Sub SubB()
MsgBox("inside SubA")

End Sub

5. Rename the two text files, so that the next time you open the spreadsheet it won't try to insert the lines from the files into the subroutines.

6. Re-open the spreadsheet. Two message boxes will now appear, one from SubA and one from SubB.

View 9 Replies View Related

Run Time Error When Calling Userform

Jan 16, 2007

I am getting a run time error # 9 when I run a macro that calls a Userform or when I try to run code in a Userform module. The code performs beautifully on my computer, but it did not work on a coworker's computer. It ended up working on 3 out of the 5 computers I have tried it on.

I have tried changing security settings to low, and a bunch of other stuff, but I cannot get the code to run on the computers that get the run time error on them when I try running the code on them.

I get the run time error when I try to load or show any userform in the workbook and I get it if I try to run code that is in the userform module. However, if I paste the code into a regular module and run it, the code runs fine.

Does anyone know what could be causing this? I don't think my code is causing the problem since it runs on some machines, I am guessing there is a setting that is preventing Excel from calling Userforms.

I have a button, Private Sub CommandButton1_Click, on a sheet that shows a userform. This is the bit of code that gets tagged with the run time error. The userform has a refedit control on it allows the user to select a cell and then hit ok to run the code or cancel to, well, cancel it.

Code for the button that gets tagged with the run time error:

Private Sub CommandButton1_Click()
frmLoadTrade.Show 'calls userform
End Sub

Code in the Userform Module:

Private Sub cmdCancel_Click()

TradeTicketSpreadsheetName = ThisWorkbook.Name
Unload Me
Workbooks(TradeTicketSpreadsheetName).Activate

End Sub

View 4 Replies View Related

Error 449: Argument Not Optional Calling UserForm

Dec 5, 2007

I call a userform from a sub menu i created it, but i got an error 449: Argument not optional.

Private Sub Workbook_Open()
Dim cControl As CommandBarPopup
On Error Resume Next 'Just in case
'*Delete existing Super Menu if it was left.
Application. CommandBars.FindControl(Tag:="MyMainMenuTag").Delete
On Error Goto 0
On Error Goto u
'*Add new Accounting Menu
Set cControl = Application.CommandBars("Worksheet Menu Bar").Controls.Add(msoControlPopup, 1, , , True)
With cControl...........................

View 7 Replies View Related

"Run-time Error '9'" Calling Userform On Some Computers

Feb 5, 2008

I get a "Run-time error '9': subscript out of range" error when calling a userform.
The code opens a reference spreadsheet then shows a userform with a combobox and two command buttons (Continue and Quit). The userform has a private initialization sub-routine to populate the combobox with values from a list on the reference spreadsheet. When the userform is called the error comes up.

Here's my problem: The code was written on my computer and saved as an Add-in. The add-in has since been installed on a number of other computers and works properly. Recently I tried to run the code and this error started popping up, don't know what changed. All versions of Excel are the same and haven't changed.

BRF = ActiveWorkbook.Name
If BRF = "Blank upload.xls" Then
Workbooks.Open path & "QC Data AnalysisQCDA ref.XLS"
OtherBRF.Show
Workbooks("QCDA ref").Close SaveChanges:=False
Goto 1
End If

View 5 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

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

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

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

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 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

Subroutine Stops Before Performing All Commands?

Jun 17, 2013

I have two subroutines. One subroutine updates some figures on spreadsheet 1, and then calls a subroutine that updates some figures on spreadsheet 2. Spreadsheet 2 is supposed to save and close, and return to spreadsheet 1, but it only gets as far as opening spreadsheet 2 and updating the figures. These are the two subroutines:

Code:
Sub UpdateLegalAndMeans()
Dim wBook As Workbook
Dim count As Integer ' counter for counting down backlog figures

[Code]....

View 4 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

Pass Variable To A Call Subroutine

Jan 18, 2007

I have a code below which need some input from user. This input will also be serve as the input of the subroutine which i am going to call. However, i do not know how to go assign this input to the subrountine which i will be calling, can anybody help ?

For example, the "input" variable will also be served as an input in subroutine test2 ...

View 6 Replies View Related

Adding Subroutine To Macro For Slowing Down Time?

Aug 10, 2014

I would like to add a "subroutine" to my macro to show the numbers it is picking. But I am having a problem figuring out how to do this.. Here is my macro...

Sub generatelottery2()

Const l& = 1 'lower value
Const u& = 49 'upper value
Const n& = 6 'number of numbers per draw

[Code]....

View 3 Replies View Related

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

Macro Call To Analysis Toolpack Subroutine

Feb 2, 2007

I know this problem has been answered before, but my browser is giving me hell when I try to use the search function, so here I am clogging up the post forum.

I would like to be able to access one of the subroutine functions built into the Analyis Toolpack add-in. Using the macro-recorder, here's what I came up with:

Application.Run "ATPVBAEN.XLA!Random", ActiveSheet.Range("$F$23"), 1, _
15600, 7, , ActiveSheet.Range("$A$3:$B$12")

I get a run-time error 1004 when executing stating that "ATPVBAEN.XLA Could Not Be Found". I'm sure this has to do with they improper way in which I'm trying to call this function.

View 9 Replies View Related







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