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


ADVERTISEMENT

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

Code Breaks Sometimes/sometimes Not: Subroutine Executed When The User Presses A Command Button

Mar 10, 2007

I have inherited support for the an Excel 'program' that seems to be fairly unstable. I am currently having problems with the following code in a subroutine (executed when the user presses a command button):

With ActiveSheet.PageSetup
.PrintTitleRows = "$1:$7"
.PrintTitleColumns = ""
.PrintArea = ActiveSheet.UsedRange
End With

Sometimes it works and sometimes I get the following error: Run-time error '1004'
Unable to set the PrintArea property of the PageSetup class.

… on the .PrintArea = ActiveSheet.UsedRange

I am having a hard time figuring out what is causing its wishy-washiness. Running the following code (launched from worksheet named 'consumer' with a command button):


Sub subConsumerFacesheet()...................

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

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

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

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

Create Range Object & Pass To A Subroutine

Apr 10, 2007

Create Range Object & Pass To A Subroutine

Sub Test(ByRef objRange As Range)
objRange.Value = "Hi"
End Sub

Sub TestTheTestMethod()
With ThisWorkbook. Sheets("Sheet1")
Set objRange = .Range(.Cells(1, 1), .Cells(i - 1, 3))
objRange.Value = "Hi" 'This works fine !
Test (objRange) 'But here... Getting ERROR 424 -- Object Required
End With
End Sub

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

Event-handler Subroutine To Transfer Checkbox Text To Cell

Mar 17, 2007

to save typing the same things over and over I have created a dialog box with checkboxes, named with several common terms we use when writing an invoice. i.e. dig a hole, paint a fence etc. I have assigned the dialog box to a button on the worksheet.

When I check the checkboxes, I want the text to go to a blank section of the invoice one underneath the other. The reading I have done suggests this is an event-handler subroutine, I just don't know enough about VBA yet to be able to write the code.

View 9 Replies View Related







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