Compile Error / Sub Or Function Not Defined
May 17, 2012
I have a two set of Macros in a workbook. One is to create a command button on a sheet and other macro will run onece the created commond button is clicked.
Macro runs fine. Command button gets created, but when I click the command button to run another macro it gives error "Compile Error: Sub or Function not defined" highlighting the code "Call Add" at the code entered for sheet. This code is added by macro in the sheet1. I am attaching a sample file as well as codes.
Sub CreateButton()
Dim Obj As Object
Dim Code As String
Sheets("Sheet1").Select
'create button
Set Obj = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
Link:=False, DisplayAsIcon:=False, Left:=600, Top:=30, Width:=100, Height:=35)
Obj.Name = "InsertInvoiceButton"
'buttonn text
[code]....
View 9 Replies
ADVERTISEMENT
Apr 9, 2014
Trring to use function edate() in VBA macro, I've activated atpvbaen.xls in Tools/Register but get compile error:"Sub or function not defined".
View 5 Replies
View Related
Jul 9, 2014
Have two worksheets in same workbook. First worksheet is "ReArrangedAddr" Which basically has a command button to click to run a "Sub" behind the second worksheet "Orig SH Register". When I click on button on first worksheet, I get error "Compile Error: Sub or Function not defined"
* * * * * code behind command button * * * * *
View 14 Replies
View Related
Jul 28, 2006
Can someone explain the concept of defining the "Sub" to me.
View 5 Replies
View Related
Mar 17, 2014
I have created the following defined function in excel VBA but i get the complie error:-
'Block if without end if'
This this the code I have written for the function:-
Public Function Rule_45(Current, Previous, Result)
' RED: 'Decreasing Trend' OR 'Same' AMBER:'Increasing Trend' GREEN:'>83%'
If Result = "-" Then
Rule_45 = "-"
[Code].....
View 2 Replies
View Related
Jun 18, 2009
I'm trying to use MATCH to identify the Column number that contains "DL_Error", then I'll use this Column # to select a cell (found Column # & "34"), but I get the error shown in the title of this post.
Here's my current
Sub Macro15()
' Macro recorded 6/18/2009 by me
Range(Match("DL_ERROR", "A31:CW31", 0) & "34").Select
End Sub
View 9 Replies
View Related
Mar 24, 2006
I receive: "Microsoft Visual Basic Compile error:
Sum or Function not defined" after I have run a macro. I recorded the macro.
The macro code is: ..
View 12 Replies
View Related
May 15, 2014
I get this error : Compile error : Sub or Function not defined. I found out that this might be caused by the solver not being referenced. But, this is fixed now but I still get the same error message.
I'm using Excel 2007 - Windows.
Here is the code :
Sub Macro1()
Dim i As Integer
Dim j As Integer
j = 4
For i = 1 To 4000
If ActiveSheet.Cell(i, 12).Value = 1 Then
ActiveSheet.Cell(j, 15).Value = ActiveSheet.Cell(i, 2)
[code].....
View 2 Replies
View Related
Jul 29, 2014
I am using Microsoft Excel 2010 and Microsoft VBA 7.0 on my system. I would like to eventually create a PowerPoint and insert charts generated in the Excel workbook. In the meantime, I cannot get the basic PowerPoint created.
The line in red is highlighted blue when the compile error "User-defined type not defined" message box appears.
Public Sub TryAgain() Dim myPowerPoint As PowerPoint.Application
'
' do nothing for now
'End Sub
I have set the references such that Microsoft Project 14.0 Object Library is indeed checked. The Excel file only contains this code in a module. All sheets are blank. Nothing else is written yet.
View 1 Replies
View Related
Aug 12, 2014
New to VBA and just trying to make some edits to some existing code. I have basically copied a pre-existing form and module and changed names from "Appendix" to "Drawing" as I am trying to replicate what the piece of code already produces for a table of appendices, for my drawings.
However, when I try and run the form I get Compile error: Variable not defined with lstDrawings highlighted.
[Code] ...........
Is this something that should be defined in my global module which I am missing?
View 3 Replies
View Related
Jan 21, 2012
The following code has been used previously to enter data from a userform to a worksheet without a problem. However, since I added some new bits of code I am getting a compile error with the message variable not defined.
Here is part of what I have so far and the bit that is highlighted after the error comes up is the 'Set ws' line;
Code:
Private Sub CommandButton1_Click()
Worksheets("Duties").Range("C5") = txtdate
Worksheets("Duties").Range("H5") = txtarea
Worksheets("Duties").Range("N5") = txttea
Set ws = Worksheets("Duties")
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
The code I have recently added:
Code:
Private Sub UserForm_Initialize()
Set wsRes = Worksheets("Resources")
With wsRes
.Range("B1", .Range("B" & Rows.Count).End(xlUp)).AdvancedFilter xlFilterCopy, , .Range("L1"), True
With .Range("L2", .Range("L" & Rows.Count).End(xlUp))
cboTeam.List = .Value
.EntireColumn.Clear
[Code] .......
View 8 Replies
View Related
Jun 30, 2014
why this would suddenly stop workin and start giving the above? Error occurs on the first GoTo ExitProc
Code:
Sub ConsolidateDataUsingFileList()
'--Purpose is open each file specified in sheet Info, then copy
' that file's data and append it to the dataset
[Code]....
View 3 Replies
View Related
May 27, 2008
I've used Excel for many years, but finally am learning VBA, using Excel Progamming for Dummies by John Walkenbach. Excel is version 2000.
I've searched extensively on Google and on the MrExcel site for the solution to my problem, but still haven't found it . Any direction would be most appreciated.
I'm trying to execute the examples in the book, and have gotten the error message "Compile error: Variable not defined" with "MyString =" highlighted with several of the examples. Could someone please tell me where I'm going astray?
Following is the latest subroutine I typed into the module, from page 124:
Option Explicit
Sub GetLength()
MyString = "Hello World"
StringLength = Len(MyString)
MsgBox StringLength
End Sub
View 9 Replies
View Related
May 6, 2009
I keep getting 'compile error - variable not defined' in the following
Sub LockIt()
TextBox1 = ""
End Sub
View 9 Replies
View Related
Jan 13, 2010
It works as a regular Module but when I put it into a "Private Sub" for a button its not working.
Basically I have a master sheet that I create Tests from. I push a button and it creates a Test for others to take. I want the macro to transfer from the Master to these so when they are done I can press a button and upload the answers to a tracking sheet.
It errors on the strSecondFile
Private Sub CommandButton1_Click()
Dim wbk As Workbook
Dim NAME As String
'strFirstFile = ActiveWorkbook
strSecondFile = Application.GetOpenFilename
Set wbk = ActiveWorkbook 'Workbooks.Open(strFirstFile)
NAME = Range("A6").Value
View 9 Replies
View Related
Jul 18, 2006
I came across a weird situation using a standard print macro. One of my users could not use the print macro due to a compile error. The row that was highlighted was
.PrintErrors = xlPrintErrorsDisplayed
the error states that the variable is not defined. I removed that line of code and everything prints fine.
I tested this code out on excel 97 and it worked; is this sensitive to OS version? Will leaving this line of code effect anything big?
View 9 Replies
View Related
Jan 27, 2014
I am trying to put two subs into a macro. They work individually, but when I put them together, I get a "Compile Error: Variable Not Defined" Message. I was told I have to define the variable in the sub multipleif(), but I am not certain as to how to do this. The error message highlights the line I have bolded below.
VB:
Option Explicit
Private Sub CommandButton1_Click()
Dim mth As Variant, txt As Variant, des As Variant, wdt As Variant, I, Cell
[Code]....
View 5 Replies
View Related
Feb 7, 2007
I am trying to run create a simple macro that copies and paste special values - something I have done 100's of times but for some reason I keep getting an error message - even though I recorded the macro and didnt write it by hand - see below:
Sub Macro6()
Cells.Select
selection.Copy
selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
For which I get 'Compile Error - Expected Function or Variable'
View 6 Replies
View Related
Mar 31, 2009
I am trying to use the Find function within some VBA code but keep encountering a compile error. Code works fine on it's own as below but doesn't work within the VBA code. I can't figure out what part of code needs to be modified.
The desired result in J2 = "Jim"
the value in cell I2 = "Jim |Anderson"
Working Function as follows:
View 3 Replies
View Related
Aug 13, 2013
Why do I get the below error when I open my workbook? The highlighted function is below.
Private Sub CommandButton1_Click()
Dim myText As Variant
If TextBox1.Value = "code" Then
UserForm1.Hide
Else
Me.Label1.Visible = True
Me.Label1.ForeColor = vbRed
End If
End Sub
View 1 Replies
View Related
Dec 18, 2013
I developed a program which uses Date function in several places. Problem is that on some machine this function is not working and I'm getting compile error.
What is the reason for that. Is this a system setting??
View 9 Replies
View Related
Jun 28, 2014
I have this code snippet..
Code:
Function appointment(ByVal day As String, ByVal hour As Integer) As String
' Insert code to return any appointment for the given day and time.
Return "appointment"
End Function
But I get this error. Compile error: Expected: end of statement
View 2 Replies
View Related
Jul 27, 2006
Need the right direction to stop the error 'Compile Error Expected Function or Variable' appearing. I have both of the following codes in a module. The AddNewTenancy works perfectly but the EditTenancy comes up with the following error.
Both the Userforms exist so I know it's not that.
Sub EditTenancy()
EditTenancy.Show
End Sub
Sub AddNewTenancy()
NewTenancy.Show
End Sub
View 2 Replies
View Related
Dec 18, 2006
i'm trying to call a function from another one, i'm getting this error 'Compiler error: = expected' but i don't know the reason, the functions simply take some values an store them in an here is the
Dim productos(19, 3) As String
Sub agregarProducto(ByVal descripcion As String, ByVal modelo As String, _
ByVal precio As String, ByVal unidad As String)
Dim r As Integer
For r = 0 To 19
If productos(r, 0) = "" Then
productos(r, 0) = descripcion
productos(r, 1) = modelo
productos(r, 2) = precio
productos(r, 3) = unidad
End If
Next
End Sub
Sub agregarProductoTelas()
Dim descripcion, modelo, precio, unidad As String
If Selection.Column = 1 Then
descripcion = Selection. Offset(0, 0).Value
modelo = Selection.Offset(0, 0).Value
precio = Selection.Offset(0, 3).Value
unidad = Selection.Offset(0, 2).Value
agregarProducto(descripcion, modelo, precio, unidad) 'error happens right here
MsgBox (descripcion)...
View 3 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
Oct 1, 2006
I have the following
Private Sub Workbook_Open()
Worksheets("Sheet1"). Range("L5").Value = Date
End Sub
When i try and run the code it returns an error saying: "Compile Error, Cant Find Project Or Library" and it highlights the word "Date"
View 7 Replies
View Related
Sep 18, 2013
I am getting "Sub or Function not defined" error in the below place of my coding. I have highiglided the code which system did and this was given by one of our commite member only
[Code start here]
Windows(Fname).Activate
If Not WorksheetExists(Date1) Then GoTo ABC
Else
[Code]....
View 2 Replies
View Related
Feb 7, 2007
A client has a registration workbook for each student which contains 3 types of worksheets, A) Transcript B) Registration and C) Grade sheets. Each file has only 1 Transcript sheet and 1 to many pairs of Registration and Grade sheets.
I have a GPA user defined function which obviously can only be used on a Grade sheet. I would like to return an Error if the user trys to use the udf on a non Grade sheet.
Currently I am just returning 1/0 but the smart tag returns #Name. Can I control the text displayed somehow?
View 9 Replies
View Related
Mar 5, 2013
I have a relatively complex report that I work with and a worksheet is no longer required. I have deleted the worksheet and reference to it hwoever when running the macro to pull all the data, it gets to the summary of all the data and i get the Run Time Error 1004 Application-defined or object-defined error pop up. ON reviewing it, it is on this line ActiveCell.Offset(0, 0).Range("a1:a" & Range_Height).Select of the below code...
VB:
Sub GetRangeName()
Sheets("TOTAL").Select
[Code].....
use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window.
View 1 Replies
View Related
Apr 26, 2009
I have a simple function below to put in different forumlas in different cells to get stock quotes. When I run this I get runtime error 1004 application-defined or object-defined error. The first formula goes through but vba chokes on the next formula: ActiveCell.Offset(I - 1, 4).Formula = username
View 10 Replies
View Related