Separating Code Creates: Run-time Error '424'
Dec 12, 2006
I've written some code that fires on a worksheet_change event. It worked fine for the initial bit of code I wrote, but then once I repeated it for several different ranges, I got an error stating COMPILE ERROR: PROCDEURE TOO LARGE. (This amount of code below works fine, it's only when I add the rest it becomes too large.)
Private Sub Worksheet_Change(ByVal Target As Range)
'Unprotect Sheet
ActiveSheet.Unprotect Password:="clemson"
'Freeze screen
Application.ScreenUpdating = False
'Turn Off Auto Calc
With Application
.Calculation = xlManual
.MaxChange = 0.001
End With
' Master Bath Shower Listello
If Not Intersect(Target, Range("Listello1ShowerMasterBath")) Is Nothing Then
If UCase(Target.Value) = "NONE" Then
Range("Listello_1_Options_Shower_Master_Bath").EntireRow.Hidden = True:
Range("Listello_2_Shower_Master_Bath").EntireRow.Hidden = True:..........
View 9 Replies
ADVERTISEMENT
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
Jan 14, 2010
Sub paste()
' paste Macro
' Macro recorded 2/20/2009 by lawryad
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
ActiveSheet.paste
ActiveSheet.paste
Application.CutCopyMode = False
ActiveSheet.Range("p1").Copy
ActiveSheet.Range("a1").Select
End Sub
Now everything works good with this code unless there is nothing copied to paste. In that case it will go to a "run-time error'1004' " I would like instead for a msg box to appear saying "You must copy required data first"
View 9 Replies
View Related
Oct 29, 2013
I need some dates showing in the correct format.
I have two worksheets, the first will have a date as shown in the attached worksheet in cell A2. This would have been pasted as a value from another source. I need this to be seperated and to show as in cells D2 and E2.
Would be ok with either a formula or macro to do this.
View 2 Replies
View Related
Dec 25, 2009
I am trying to use the Left function in my VBA code but continue to receive run time error 1004 - Method 'range' of object '_global' failed. Not sure if the error originates for code being written incorrectly or if the left function is not available in VBA. I am basically trying to take the first 9-characters for each cell in column K and copy the values to column G.
View 3 Replies
View Related
May 9, 2008
This piece of code runs perfectly on its own but when called at the end of another code it fails and I haven't a clue why. The reference wsTmp is dim'd globally and defined in the main component where it is simply - worksheets("somename")
Run-time error '1004':
The sort reference is not valid. Make sure that it's within the data you want to sort, and the first Sort By box isn't the same or blank.
Private Sub FinalSort()
wsTmp.Cells.Sort Key1:=Range("D2"), Order1:=xlAscending, Key2:=Range("A2") _
, Order2:=xlAscending, Key3:=Range("K2"), Order3:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
End Sub
View 9 Replies
View Related
Oct 20, 2009
I have a workbook with multiple sheets. Is there a tool that creates a menu bar or code that I can add that would support navigation?
My goal is to have something with approximately 4 options (buttons?). They would link to 4 different sheets that serve as indexes within the workbook.
I know I can add a control like a button to a given sheet that would take the user to given sheet when clicked, but can I make the button 'float' above all the sheets, or add to a menu bar, or something? I just don't want to have to add the button to every sheet in the workbook.
I am looking for something simple/easy, and am not looking for anybody to do the work. I just have no idea on how to approach the problem.
View 11 Replies
View Related
Oct 8, 2008
I have written a Excel (2003) that searches a worksheet for a string in any cell. If the string is not found, it uses the 'On Error GoTo' command to jump to a given label. It works fine on the first string not found. When it searches for the next non-existent string, it fails with:
'Run-time error '91':
Object variable or With block variable not set'
Do I have to clear a buffer after each cells.find search?
My
View 7 Replies
View Related
Oct 10, 2006
I'm not sure why this is happening, but every other time I run this one specific macro, I get a "Run-time error '1004': Paste method of Worksheet class failed". I even tried running this macro, then running a different one, then running this again, but I still got the error every other time.
Every time I get the error, it highlights this line of
Sheets("Regenerate Request").Paste
This is all of the code up to where I get the error:
Sub YesRegen()
' after user has hit Yes on the RegenerateRequest macro, this posts the new request to
' the log, generates the new file and attaches it to an email
Application.Run "LogUnprotect"
Range(Range("A" & ActiveCell.Row), Range("K" & ActiveCell.Row)).Copy
'Selection.Copy
Sheets("Regenerate Request").Activate
Application.Run "RegenFormUnprotect"
Range("A40:K40").Select
Range("A40").Activate
Sheets("Regenerate Request").Paste
View 10 Replies
View Related
Mar 4, 2010
I havet he following code which sorts data. If there is no data to sort I keep on getting a run time error. Could I add something to my code to prevent the run-time error, as sometime there won't be any data to sort. The code runs when I switch to the worksheet in question.
Sub SortMeetings()
Dim iCTR As Integer
Dim yCTR As Integer
Dim zCTR As Integer
zCTR = 11
For iCTR = 12 To 23
For yCTR = 1 To 10
If Len(Range("D" & iCTR).Offset(0, yCTR)) 0 Then
Range("AA" & zCTR).Value = Format(Range("D" & iCTR).Offset(0, yCTR), "HH:MM") & " " & Range("D" & iCTR).Value
zCTR = zCTR + 1
End If
Next yCTR
Next iCTR
Range("AA11:AA" & zCTR).Select
Selection.Sort Key1:=Range("AA11"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub
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
Aug 12, 2009
Run-time error '1004' Application-defined or object-defined error. I am trying to use this
View 2 Replies
View Related
Oct 4, 2009
I was trying to use the below code
View 4 Replies
View Related
Aug 17, 2008
For some reason my form won't open when the workbook is opened. I get an error message "run time error '424' object required" (which happens when I have Form1.show in the BOTH workbook_open event and the userform_initialize event (oops)). When I removed form1.show from the userform_initialize I don't get an error but I also get no form. I recall having this issue before but I can't recall how to fix it.
Can I call the userform_initialize event from the workbook open event to get around this successfully and properly?
View 9 Replies
View Related
Dec 4, 2009
I keep getting a Run Time Error 1004 (Application Defined or Object Defined Error) when my sub reaches this line:
ActiveCell.Formula = "=SUM(D222,D224,D226,D227,D229,...)"
In the actual line of code the "..." above is another 20-30 or so cells in column "D". Probably no more than 150-170 characters in the line.
If I remove half of the cell range names it works, but I need all of the cell ranges for the equation.
View 9 Replies
View Related
Jan 28, 2009
I added a new sub to and now I'm getting a compile error. This was working fine until I added "Cust_Rev1". I get an compile error saying "expected variable or procedure, not module". Both are located in personal.xlsb. If I rem Cust_Rev1 out, I don't get a hiccup. (FWIW, I've been running "Cust_Rev1" on its own to debug it.)
View 2 Replies
View Related
Jan 17, 2009
I am having a problem trying to create a macro that will loop in order to create several macros. I have a long macro (call it mainmacro) that needs to be able to create several simple macros to be used by the user of the workbook. Each macro has a variable that needs to be taken from mainmacro. Each macro is different based on the value of the 'i' loop variable that the macro is created in. i'm sure im making this sound more complicated than it really is...basically:
Sub mainmacro()
'lots of code not relavent to this issue here
For i = 1 to 10
'create 10 macros that, when run, would highlight A1, A2, etc.
Range("A" & i).Select
Next i
End Sub
This is just an example. But, basically, i just want to be able to automatically create a bunch of macros with a variable from mainmacro.!
View 11 Replies
View Related
Feb 15, 2007
I have a list on my first worksheet that is sequentially numbered in the first column, and has work activities in the next column. On my second worksheet, I have those sequential activity numbers as the column headers on a new list. Problem is I don't have any room to label the new list by the activity's actual description(second column, first sheet). If I did, I would just use a simple VLOOKUP.
So, what I would like to do is utilize the VLOOKUP to pass the activity description string to a UDF that will create a comment in those column headers. Then when the user mouses over the activity numbers, the respective activity descripiton will pop-up as a comment thus solving my space problem!
View 8 Replies
View Related
Oct 21, 2008
run time error 91 ...
View 14 Replies
View Related
Nov 12, 2008
I have the following code in a macro and when it is run I get a Run Time Error 438 Object doesn't support this property or method. This occurs at the first occurrance of the destination/source.
View 5 Replies
View Related
Feb 26, 2009
I have the main form completed and everything appears to be in order. So I made a button on the first sheet that simply calls for the main form to be shown. However, every time I click it, I get the run time error 424 object needed thing. I don't understand because the button is calling the form and the names are all correct. When I click debug, it takes me to the small code for the start button. Below are the codes for the start button and the main form.
View 10 Replies
View Related
Dec 11, 2009
I have a line of code to enter a date on a spreadsheet from a user form:
View 2 Replies
View Related
Jan 25, 2010
Getting a run time '424' error with following code (object not defined). Not sure if I have it set up correctly.
View 6 Replies
View Related
May 4, 2007
I am getting Run-time error '91':
Object variable or With Block variable not set
In my mind everything checks out, but I am still very new to all this.
Here is the
'Shifts cells to make space for inserted VFD
Dim CheckBoxes As Integer
Dim UpLeft
Dim LowRight
Dim CountCells As Integer
Dim MoveTo As Range
View 9 Replies
View Related
Sep 10, 2007
I'm gathering and ordering data. It's in the biotech field so I have to work with a lot of reaction formulae and compound abbreviations. Alas those are not standardized. So I have gathered all the compounds used by different organisms and standardized their abberviations and I want to replace the abbreviations used in the reaction formulae of the organisms with the standardized abbreviations so I can compare the formula with each other.
This resulted in a list of formulae, and a list of 2 columns, 1 the old abbreviations and the other the new abbreviations. I wrote a macro to pick an abbreviation out of the old abbr column and find it in the formula list. Then the old abbreviation should be replaced with the new abbreviation.
I got it working but the problem is that some abbreviations are longer than others and thus the smaller ones may resemble letter combinations in the larger ones. This can easily be solved by sorting the abbreviation list so that the largest abbreviations are on top and will be checked first. However, after I did this the macro didn't function any more. I have no clue what to do.
Sub ReplaceAbbrBoroWithGeneral() ...
View 9 Replies
View Related
Jun 25, 2008
I am getting a run time error and highlighting this section of code.
The entire code I am using is below. This has worked fine on my maching
now trying to use it on another exact machine I am getting this error.
The way the code works..
It navigates to a webpage that allows the user to download the data which is called
DownloadNCPartListServlet.
Windows("DownloadNCPartListServlet").Activate
I think I may need to tweek the .xls file extention properties. What do you think?
Public Sub SKPIUPDATE()
Dim QPR
Dim lnk
Dim frm
Dim start
Dim fin
Dim drp1
Dim drp2
Dim src1
Dim NAMC As Integer
' This macro will automatically open and download the TMMK-VEH daily scrap
'and store the file in the same directory
Set QPR = CreateObject("InternetExplorer.application")
QPR.Visible = True
View 9 Replies
View Related
Jul 27, 2008
I'm using the code
'Changes labels from zip code entry
Private Sub Textbillingzip_change()
Label42.Caption = Sheets("lists").Columns(10).Find(Textbillingzip.Value).Offset(0, 1).Value
Label43.Caption = Sheets("lists").Columns(10).Find(Textbillingzip.Value).Offset(0, 2).Value
End Sub
Private Sub Textsetupzip_change()
Label44.Caption = Sheets("lists").Columns(10).Find(Textsetupzip.Value).Offset(0, 1).Value
Label45.Caption = Sheets("lists").Columns(10).Find(Textsetupzip.Value).Offset(0, 2).Value
Label46.Caption = "Zone " & Sheets("lists").Columns(10).Find(Textsetupzip.Value).Offset(0, 3).Value
End Sub
I would like to have some error message pop up (or something else) rather than the current Run Time '91' error when the imput from either textbox is not found on the sheet "Lists"
View 9 Replies
View Related
Jul 31, 2009
I've written this macro to get data from a .csv and import into my spreadsheet however I get an intermittent "400" error, when I get the msg it says "method 'range' of object' _global failed".
Sub get_confirm_file_from_inbox()
Dim strPath As String
Dim strFile As String
Dim wbname As String
On Error GoTo Errorcatch
wbname = ActiveWorkbook.Name
strPath = "C:xxxManageCentralinbox"
strFile = Dir(strPath & "confirm*.csv")
Do While strFile ""
Workbooks(wbname).Activate
Sheets("Confirm_Data").Activate
Range("A3:BK").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.ClearContents...................
View 9 Replies
View Related
Mar 1, 2010
i have a problem in using vba and each time I run my project I get
Runtime error "9" Subscript out of range :'(
and the line of code in question is:
pr_pri.Worksheets("wspr_pri").Cells(13, 4).Activate
here's the entire code for the macro:
Sub prpri()
Dim i%, j%, k%
Dim iLRA As String, iLRN As String
Dim Y As Boolean, Ys As Boolean
Dim TabloA(), TabloN()
View 9 Replies
View Related