Run-time Error Every Other Time The Macro Runs
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 Complete Thread with Replies
Sponsored Links:
Related Forum Messages:
Macro Run Time Error 91
Sub asdf() Dim c As Range Dim x As Long Dim y As Integer Set c = Columns("A:B"). Find(" Total", lookat:=xlWhole) x = c.Row For y = 15 To 4 Step -1 If Cells(x, y) = 0 Then Columns(y).Delete Next y End Sub However, it errors out at x = c.Row Saying "object variable or With block variable not set" I have xl2000. Could this be the problem? With the code I'm trying to locate my "Total" row. Then delete all columns from D:O with a value of zero. An example sheet is supplied at the link.
View Replies!
View Related
A Macro Setting That Would Cause A Run-time Error 1004
Is there a setting within excel that could cause a user to get a run-time error 1004? I have a workbook with a macro that adds additional sheets to the workbook when a button is clicked. The thing works fine on my machine and 3 or 4 other machines that I have had guys test it out, but I have a user that it will not work for. He is at a location about 3 hours away so I cant see exactly what he is doing, but he says after he clicks the button he gets a run-time error 1004 that says "Unable to set the PrintQuality property of the Page Setup class". I'm thinking that it is a setting within excel?
View Replies!
View Related
Unexpected Run Time Error 1004 In Macro
I have a macro, operating in my excel document. It works and does it's function. The only problem is every time this macro is running I get the run time error 1004, Method 'SaveAs' of object '_Workbook' failed. After clicking End in the error window it opens up a newly created sheet that I need. I don't need to save the file in the desktop, I need it just to open up like it does right now.
View Replies!
View Related
Sort Macro: Run-time Error 1004
I have created a macro which sorts 4 columns of data in asceding order numerically. I have assigned this macro to a button so that when the button is clicked, the columns of data are sorted. Unfortunately when the button is pressed i get a vba run-time error 1004. I havent a clue how to resolve this. I recorded the macro useing the excel recorder function as opposed to typing it out manually. The code created is given below. If i click debug when the error pops up, the code referring to column f:f is highlighted yellow.
View Replies!
View Related
Run Time Error 1004 (macro Called From Access Module)
i am running a macro thru vba (beiing called from a ms access module) and am getting a RuntTimeError 1004. the code opens a workbook...then open a second workbook (which houses the macro) then activates the desired worksheet and call the Maco via the run command but errors out. if i open the workbook and set focus on the desired sheet ....tool>macro>desired macro name it runs fine. the line of code in the macro is: "ActiveCell.Offset(1, 0).Activate"
View Replies!
View Related
Macro To Move A Cell Right Every Time It Runs
I have a spreadsheet with sales figures for a company over a few months. I want to create a macro that will insert a new month after the last month. I have got it to work for the first month but after that it will just insert 2 black cells after. i have a named cell called Average_slales_per_month that is next to the last month all the time.
View Replies!
View Related
Protecting Worksheet With Macro (Run Time Error '1004')
I am using the following code to enable users of a form to made make selections by adding a tick in one of the boxes by clicking on it. It works fine with thesheet unpotected but when I protect the sheet with cells E33:k33 unlocked i get Run Time Error '1004' Unable to set the Name property of the font class.When I debug, Target.Font.Name = "Marlett" is highlighted.
View Replies!
View Related
2007 Macro: Run-time Error 91:Object Variable Or With Block Variable Not Set
I'm fairly new to macro's and VBA, by searching on the internet i've copied and pasted some code together into a macro. But it ends in a Run-time error 91... The macro opens a target .xls file in a selected folder, performs copy - paste actions from masterfile to targetfile. Than it filters data in the targetfile sheet1 and copy's the results to the various other sheets; saves and closes the targetfile. The next target file in the folder is opened and the actions are repeated in this second target file. For the first target file this works smoothly; but for the second one (of a total of around 100) it does not copy the filter results to the other sheets in this workbook. The error message i get is: "Run-time error 91:Object variable or with block variable not set." When i hit debug it highlights the line "ActiveSheet.Next.Select" which, at least in the first file, seems ok.
View Replies!
View Related
Run-time Error '1004' :: Copying Data From Other Sheets By Macro
I've been trying to use the below code, Sub combine() 'This will copy data from all sheets of the selected workbooks 'To a sheet named 'Data' in the sheet in which the macro is run from Dim pasterow As String mainsheetname = ActiveWorkbook.Name MsgBox ("Please select spreadsheets to combine") filestoopen = Application.GetOpenFilename(MultiSelect:=True)...
View Replies!
View Related
Run-time Error
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 Replies!
View Related
Run Time Error 9
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 Replies!
View Related
Run-Time 91 Error
why my code fails at the point labelled (Run-Time 91 error). From reading the help I think it has something to do with using a set statement within a with...end with block, but I'm not sure. Sub GetReport() Dim ReportName As Variant Dim Reportwkbk As Workbook, Dbasewkbk As Workbook Dim Reportwksh As Worksheet, Dbasewksh As Worksheet Dim AgentName As String, Extension As String Dim dtmDateStart As Date, dtmDateStop As Date Dim i As Integer, x As Integer Dim FindAgent As Range ' On Error GoTo ErrorHandler ReportName = Application. GetOpenFilename("Excel Files(*.xls),*.xls" _ , , "Select Report to Import") If ReportName = False Then MsgBox "No report was" & vbCrLf & "selected.", vbExclamation, _ "Report Error" Else With Application ...........................
View Replies!
View Related
Run Time Error 91 ..
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 Replies!
View Related
Run-time Error 9
I have this code to know if a workbook is open, and then open if it isn't. This code was running well since this morning. I don't know what I touched to make it not to work. Public Function IsOpen(FileName) As Boolean Dim myBook As Workbook Set myBook = Workbooks(FileName) 'Here is the Run-time error If myBook Is Nothing Then IsOpen = False Else IsOpen = True End If End Function The Workbook FileName is not open, this code crashed when i tried to test what happens when is not open.ç Heyyy, I solved it. I have to put the next line On Error Resume Next
View Replies!
View Related
Run Time Error 6 - Overflow
I've been contracted some work and I was asked to add an additional metric on the report summary page. I have completed adding metric, tested it, and everything works fine. I was asked to put the code I worked on into an updated copy and thats where I get this "Run Time Error 6 - OverFlow" error message. The only difference between the two files is that the data worksheet (where the Summary page gets the info) in the new file has 100 more row of data. I understand that the code may be stuck in a loop, but what would cause this? A little background on what the file does. Every month the user enters the publication name, whether it is a color or black or white ad, and the size of the ad. The macro then summerizes the data onto a different worksheet (similar to what the results of a pivot table would give you), calculating the revenue for each publicaton (based on b/w x rate + color x rate). The file worked fine until I replaced the old data with the new data.
View Replies!
View Related
For Each Loop Run Time Error
I have created a macro to calculate data and add it to sheets over sheet 3. It has to do this for any number of sheets above sheet 3. Below is the code i have created i am just getting an error at runtime which i dont know how to resolve or what i have done wrong
View Replies!
View Related
Save As- Getting Run Time Error 91
I have got the code below, I am trying to save as file name with it ending with upload, however I am getting run time error 91, 'Worksheet save as upload name Dim Wk As Workbook ActiveWorkbook.SaveAs Filename:=FileDrive & Wk.Name & "Uploads" & ".xls", _ FileFormat:=xlNormal
View Replies!
View Related
VB Run-time Error 1004
I am receiving the error: Run-time error 1004 Application-defined or object-defined error. It is occuring on the line of Selection.QueryTable.Refresh BackgroundQuery:=False. I am using SQL '05, Excel '03, and VB 6.3. I am trying to run a SQL stored procedure into Excel. So far all of my VB code seems to be running fine.
View Replies!
View Related
Run Time Error 400
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 Replies!
View Related
Run Time Error 6 Overflow
I have code that performs calculations, adding to counters and division. All of my Dim statements are set to Long but I still get them. The code works sometimes but other times not. Do you get that error when trying to divide by zero? Anyone have any idea what to try next?
View Replies!
View Related
Run-time Error 9 On Activate
Learning VB6 by trial and error from code snippits on the web, however, am embarrassed to say I can't solve this simple one: Trying to Open an Excel sheet and read it from VB6 code written in another Excel file.
View Replies!
View Related
VB Works On One PC, Not On Another (Run-time Error 9 )
I run PCs at work and at home. Both machines run Windows XP and Office 2007 Home PC: Windows XP Home edition Version 5.1 (Service Pack 3) Excel 2007 SP1 MSO Work PC:Windows XP Professional version 5.1 (Service Pack 3) Excel 2007 SP1 MSO The VB was created on the home PC. It works. On the Work PC it crashes on the line with bold. Run-time error 9 - Subscript out of range. This have never happened before (or with any other VB routine). I also changed fileNew to include the full path, but same error. What has caused this? I suspect it’s the 'fileNew'.
View Replies!
View Related
Run Time Error 438
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 Replies!
View Related
Run-time Error 424
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 Replies!
View Related
Run Time Error 1004
I am using the below code to select some spreadsheets under a folder, open them, select the entire font, change it to Arial and close the file. I am passing the file names from Column A and calling the below procedure in a loop. Everything works fine except the below problem. If the file name I passed doesn't exist or the file is not accessable, I am getting an error message "File cannot be accessed. The file may be read only......" with two options "Retry" and "Cancel". When I click Cancel , it takes me to my code and stops at the line marked in red with Run-Time error '1004', Method 'Open' of Object 'Workbooks' failed. When the above error occurs , I need to just pass the value "ERROR" to ErrMsg filed and proceed further with the next file name. Sub ChangeFont(FileName As String) Dim objXL, objWb, objR ' Excel object variables Dim Title, Text, tmp, i, j, file, name Dim strPathToSaveTo As String Dim strFileName As String Dim wkb As Workbook Dim wkb2Print As Workbook strFileName = FileName Application. ScreenUpdating = False Set wkb2Print = Workbooks.Open(strFileName) Cells.Select With Selection.Font .name = "Arial" .............
View Replies!
View Related
Run-time Error 438
I am trying to print a form from a CommandButton. I am getting 'Run-time error 438 'Object doesn't support this property or method With this code on the worksheet: ActiveSheet.PageSetup.PrintArea = "PrintInv01" Application.PrintOut ActivePrinter:="Auto HP DeskJet 895Cse on FILESERVER on Ne10:" ActiveSheet.PageSetup.PrintArea = "" Debug highlights the second line.
View Replies!
View Related
Run-time Error 380
I have a userform with several comboboxes. When I hit the "next" button, it goes to the next row down, but if that is empty, then I'll get an error of: Runtime error '380' Could not set the Value property. Invalid property value. Here's the basics of my code. I will be more than willing to email the file. It's too large to post. Private Sub LoadRow() txtTapeNumber.Text = ActiveCell.Value txtCode.Text = ActiveCell. Offset(0, 1) cboChannel.Value = ActiveCell.Offset(0, 2) <--error here cboBrand.Value = ActiveCell.Offset(0, 3) cboFormat.Value = ActiveCell.Offset(0, 4) cboLength.Value = ActiveCell.Offset(0, 5) cboCategory.Value = ActiveCell.Offset(0, 6) cboVersion.Value = ActiveCell.Offset(0, 7) txtTapeTitle.Text = ActiveCell.Offset(0, 10) txtKeywords.Text = ActiveCell.Offset(0, 11) etc...(more txt boxes) Here is my next button code...
View Replies!
View Related
VBScript Error Run-Time 1004
I have been working on the following worksheet, which has A3-Z27 cells right now and will grow/shrink with time. The spreadsheet shown below is just a portion of the entire worksheet. My vbscript is below the worksheet. I have two worksheets PL Dbase and Waiting List. I am copying columns B thru G from Waiting List if Column J is = to "Yes". To the next available row in worksheet PL Dbase columns B thru G...These columns have the same headings on both worksheets. I am getting the following error, when I click the button I assigned the macro to: Run-Time Error 1004 Copy Method of Range Class Failed. Waiting List .....
View Replies!
View Related
Run Time Error 1004 - Autofilter
I have 4 command buttons (A-D) so that the users can update after inputting new or revised Data. My problem is that if updated in order, button D Macro below stops at the first "Selection.AutoFilter..." as if it cannot turn on the Auto Filter. It will run if I manually set the AutoFilter on the sheet. I think, and as I am completely new to this please feel free to correct me, the reason that it stops is that on the Button B is a "AdvancedFilter" Macro.
View Replies!
View Related
Run-time Error 9 When Upgrading To 2007
Our office has recently upgraded from Excel 2003 to Excel 2007, and now I am having an error message with my workbook. The error is as follows: Run-time error '9': Subscript out of range I believe I have all the macro security settings set up, however, I think this is a problem with a printing macro I had help with here. It was created to print the number of pages entered into a specified cell when the Print button was clicked - I think 2007 uses a slightly different button called 'Quick Print'? I'm just guessing here - but when I hit the Quick Print button, the Print Options box appears instead of immediately printing.
View Replies!
View Related
Subtotals Error (run Time 1004)
I have inherited a spreadsheet and code that I don't understand much about. I have code Range("B4").Select ActiveSheet.PivotTables("Kh07Pivot").PivotFields("Specialty").Subtotals = Array(False, _ False, False, False, False, False, False, False, False, False, False, False, _ False, False, False, False, False, False, False, False, False, False, False, _ False, False, False, False, False, False, False) which error (run time 1004) and says 'unable to set the SubTotals property of the PivotField class'. If I make the number of False's equal to 12, then it doesn't error. However I don't know whether it is having an adverse effect on the data?
View Replies!
View Related
Run Time Error 9 : Subscript Out Of Range
This program is supposed to take the value in two combo boxes and use them to populate pivot charts that are in other spreadsheets. So a user would select PS and AMI on sheet one (s) and it would change the pivot table on s1-s9 to look up those chosen fields. I keep getting a subscript out of range error, and I'm not sure if my pivottable.pivotlayout method is correct, but when I recorded a macro (in the very bottom) using activesheet, it worked. How can I fix this? The error occurs at the first large text, the second large text is the recorded macro.
View Replies!
View Related
Run Time Error Message 1004
Every time I run it I get a Run Time Error Message 1004 when trying to custome sort on D4. Rng2.Select With Selection .Validation.Delete .Sort Key1:=Range("A4"), Order1:=xlAscending, Header:=xlYes .Sort Key1:=Range("D4"), Order1:=xlAscending, Header:=xlYes, _ OrderCustom:="L,M,H,Contract", DataOption:=xlSortNormal End With
View Replies!
View Related
Run Time Error 9 - Subscript Out Of Range
I am trying to copy from a text file to excel workbook... Thw work book have 3 sheets: Sheet1, Sheet2, Sheet3 Now i want my macro to write into row D of Sheet2... Sub copy_txt_files() Dim FSO As Object, Folder As Object, file As Object Dim copyFrom As Workbook Dim wksCopyTo As Worksheet, wksCopyFrom As Worksheet Dim rngCopyTo As Range, rngCopyFrom As Range Set wksCopyTo = ThisWorkbook.Sheets(2) Set FSO = CreateObject("Scripting.FileSystemObject") Set Folder = FSO.GetFolder("C:logs") For Each file In Folder.Files If LCase(Right(file.Name, 4)) = ".txt" Then Set copyFrom = Workbooks.Open("C:logs" & file.Name) Set wksCopyFrom = copyFrom.Sheets(1) Set rngCopyFrom = wksCopyFrom.Range("D1") Set rngCopyFrom = wksCopyFrom.Range(rngCopyFrom, _ rngCopyFrom.SpecialCells(xlCellTypeLastCell))...............
View Replies!
View Related
VB Run Time Error -2147467259 On Start-up
I get the following VB pop-up every time I start Excel 2007 (I can't easily find a way to paste an image here, so plain text is used): Microsoft Visual Basic Run-time error '-2147467259 (80004005)': Method 'Add' of object 'CommandBarControls' failed Continue End I suspect it's a keyboard shortcut for launching some other application that is in conflict with an Excel shortcut, but I can't debug, so I can't determine this. Excel opens up fine when I click End.
View Replies!
View Related
Run-time Error 13 Type Mismatch
I am dimensioning my variable as a Date, which it is! But I keep getting this error. Public TargetRow As Integer Sub InitializeTargetRow() TargetRow = 4 End Sub ''''''''''''''''''''''''''''' ' ColorIndex 43 is GREEN ' ' ColorIndex 3 is RED ' ' ColorIndex 6 is YELLOW ' ' ColorIndex -4142 is NONE ' ''''''''''''''''''''''''''''' Sub HighlightRow() Application.ScreenUpdating = False Application.EnableEvents = False Application.Calculation = xlCalculationManual..................
View Replies!
View Related
Run Time Error - Type Mismatch
I have attached a sample file for you to easy reference. So when the code run until the loop function, it will prompt an error message. The idea is to open the selected file and the copy the data from the selected to this master file by searching the column A. Column A has the identical text in all the files that are to be copied from.
View Replies!
View Related
Run-time Error 13 On Deleting Rows
I'm not the sharpest tool in the shed when it comes to excel programming but I manage. However, I can't seem to get rid of this run-time error 13. Could anyone take a quick peek at the document and spot the problem? My intention is this, when typing 'Yes' in the AB column on a certain row, that row is cut from that worksheet and moved to the 'Archive' worksheet, also, simultaneously, I want to send a mail to a specific address. Here is when I run into the error, I suspect when the row is removed with the 'Yes', those two macros clash.
View Replies!
View Related
Run Time Error 13 Type Mismatch ...
if there is any thing need to corrected please let me know i have read rules and tried to comply all here is my question I m receiving runt time error 13 type mismatch and could not resolve it till now. if some body can look into it and kindkly give some suggestions Sub LineHours_Calc() Dim itms As Integer Dim qnty As Integer Dim upt As Integer Dim get1 As Integer Dim get2 As Integer Dim get3 As Integer Dim get4 As Integer Dim chg1 As Integer Dim chg2 As Integer Dim co As Integer Dim lhc1 As Integer Dim itm As Integer error is in 3rd line in the inner for loop i pasted the line here as well (qnty = WorksheetFunction.Index(Range("board!$B$3:board!$DZ$500"), get1, get2)
View Replies!
View Related
Run Time Error 13 Type Mismatch
I can't understand why I am getting the above message on the code below. I have used it before in other spreadsheets with the same type of data. Basically the macro should trim the data and get rid of any numbers at the start of the data (the data sometime has just a name other times it has a number then a name). In this case the data has 154 before the name. I am getting the above message on the section in Bold. As l is a string I would have though it could take both text and numbers. I have also tried it with Variant as the type and got the same result. I also dont't undertand why the error happens at this point rather than when Ls value is first determined. Dim lastrowdatab, i As Long Dim j, l As String lastrowdatab = Cells(Rows.Count, 1).End(xlUp).Row For i = 4 To lastrowdatab j = WorksheetFunction.Trim(Cells(i, 29)) Cells(i, 29).Value = WorksheetFunction.Proper(j)
View Replies!
View Related
VBA Run-time Error -2147414848
I have to create individualized reports for our reps. To do so I have created one master template that contains the data that I need. The idea is to use VBA to perform the following steps: - Loop through a list of the reps - Filter the data in the template for selected rep - Recalculate - Save off that rep-specific version - Open the just-saved rep-specific version - Loop through each sheet in rep report and delete rows that contain no data (all 0's) - Save Rep version - Close Rep version I have code that works effectively...sometimes. As in I can run the module successfully for all reports, but on subsequent runs I receive the dreaded "Run-time Error -2147417848 (80010108): Method PasteSpecial of object Range failed" when a I attempt a PasteSpecial on the first rep-specific version I open. At various times while messing with the code I have also received the same run-time error, but with the message "Automation Error. The object invoked has disconnected from its clients" After reading every post I could find on this, I was directed to MSKB Q319832, dealing with unqualified code and global objects in Office. I'm almost positive this is the issue I have - that my references to the rep-specific workbook object is unqualified, hence causing the run-time errors. My problem is that I don't understand how to qualify objects correctly. This is what I'm hoping someone can help me with. The following is what I believe to be the part of my code that is relevant to this issue Dim wbORep As Workbook Dim wsORep As Worksheet Dim strFileName As String ' path for rep-version report Set wbORep = Nothing
View Replies!
View Related
|