Spreadsheet Planet

Excel VBA Runtime Error 1004

When running VBA code, it’s common to encounter runtime error 1004, called “error 1004.”

Some error messages displayed by VBA to define the error are self-explanatory, but others are cryptic, making it difficult to tell the problem causing the error.

In this tutorial, we will discuss eight common reasons you might encounter the VBA runtime error 1004 and provide some solutions to resolve it.

Table of Contents

What is the VBA Runtime Error 1004?

Runtime errors are those errors that occur when you run the VBA code.

Usually, a runtime error makes the VBA code stop, and the user is shown a dialog box. This box reveals the error number along with a description of the error.

VBA Runtime Error 1004 is a common runtime error that occurs when working with Microsoft Excel macros and, more broadly, with VBA in the Microsoft Office suite. This error is usually associated with the way the program interacts with objects, data, or properties within Excel.

The exact text of the error message can vary based on the specific issue encountered, but it typically reads something like:

Here’s what this error generally means:

  • Application-defined : This means the error was triggered by the Microsoft Excel application itself. This can be due to issues like incompatible Excel versions, file corruption, or resource constraints.
  • Object-defined : This means the error was triggered by a specific object within the Excel application, usually due to a misreference or misuse in the VBA code.

There can be several causes for this error, such as:

  • Incorrect Referencing : This occurs when a specific worksheet, cell, or range that the VBA code is trying to access does not exist or is not correctly referenced.
  • Workbook or Worksheet Issues : Trying to manipulate a workbook or worksheet that’s closed, not yet opened, or does not exist.
  • Protection : Attempting to modify a protected worksheet or a locked cell.
  • Method or Property Errors : Using a method or property that isn’t allowed or doesn’t apply to the object being referenced.
  • Copy-Paste Issues : Trying to use copy-and-paste methods in VBA, especially if ranges aren’t defined or are overlapping.
  • Data Validation : Trying to set or modify data that does not fit the validation rules set for a particular cell or range.
  • External References : Problems related to linking or referencing external sources, especially if they’re inaccessible.

To resolve the error, it’s essential to identify the specific line causing the issue and understand the context in which the error arises. Debugging tools within the VBA editor , such as breakpoints and the Immediate Window, can be handy in narrowing down and addressing the cause of the error.

Now let’s looks at some example where VBA throws the Runtime Error 1004, and how to to fix it.

Reason #1: VBA Code Refers to Range that Doesn’t Exist

 We want to use an Excel VBA code to add the number of sales reps in cell B5.

Dataset for VBA

If we run the below code, we will get the error message “Run-time error ‘1004’: Application-defined or object-defined error.”

The runtime 1004 error in this example occurs because the sixth line of the code mistakenly refers to a non-existent cell, Cells (0,2). In Excel, row numbers start from 1, so Cells(0, 2) is not a valid reference.

Line causing the VBA Runtime Error 1004

How to Fix?

When working with ranges, ensure the specified range is valid and exists in the worksheet. Invalid references will result in a 1004 error.

Double-check cell references in the code before executing it. In this example, the correct cell reference in the sixth line of the code should be Cells (5,2).

Reason #2: VBA Code Refers to a Misspelled or Non-existent Named Range 

Suppose you have a worksheet containing a range called “Expenses.”

If you execute the following code, you will get the error message “Run-time error ‘1004’: Expecting Object to be Local”

The error 1004 occurs because the name of the named range is misspelled in the third line of the code.

VBA Runtime Error 1004 cause of misspelled named range

Note: This error can also happen if the code refers to a named range that doesn’t exist in the target worksheet. 

Double-check the references to named ranges in the code before executing it. In this example, we must correct the misspelled name.

Reason #3: VBA Code Attempts to Rename a Worksheet to Name Already Taken

Imagine a workbook with two worksheets, “Sheet1” and “Sheet2.”

The code below will result in the error message “ Run-time error ‘1004’: That name is already taken. Try a different one ” because it tries to rename “Sheet1” to “Sheet2”, which is already in use.

The error message is self-explanatory. Rename the worksheet to a name that is not already in use.

Reason #4: VBA Code Attempts to Select Range on a Worksheet that is Not Active

Imagine you have a workbook containing two worksheets: “Sheet1” and “Sheet2”. Currently, “Sheet2” is the active worksheet.

The code below will result in the error message “Run-time error ‘1004’: Select method of Range class failed” because it tries to select a range on “Sheet1” that is not the active sheet when running the code.

You can first select the target worksheet in the Excel window to activate it before executing the code.

Or, better still, insert a line in the code that activates the target worksheet. In our example, we have inserted a line that activates “Sheet1” before range selection:

Reason #5: The VBA Code Attempts to Open a File that is Moved, Renamed, or Deleted

We had a workbook called “Example” in the “Excel Tutorials” folder on the C drive, but it has been moved, deleted, or renamed.

If we run the following code to open the file:

The code executes and displays the error message “Sorry, we couldn’t find C: \Excel Tutorials\Example. xlsx. Is it possible it was moved, renamed, or deleted?”

VBA Runtime Error 1004 file moved

The error message is self-explanatory. Double-check that the file referred to in the code exists in the target folder and is not renamed.

Reason #6: Syntax Error in VBA Code

The example code below will result in error 1004, and VBA will display the error message “Run-time error ‘1004’: Method ‘Range’ of object ‘_Global’ failed.”

The example code results in error 1004 because it has a syntax error. The ‘Range’ object expects cell references to be specified as strings, not numeric values. 

To fix the error, you should feed the ‘Range’ object with cell references in the form of strings enclosed in double quotes. Here’s the corrected code:

Reason #7: VBA Code Attempts to Incorrectly Open File That is Not an Excel File

The following example code results in error 1004, and VBA displays the error message “Run-time error ‘1004’: Excel VBA Hyperlinks.docx: file format is not valid.”

The error 1004 happens because the code uses the “Open” method of the “Workbooks” object to try and open a Word file.

You can only use the “Open” method of the “Workbooks” object to open Excel files. 

To open a Word file in Excel, use the code below, which you can adjust to your needs.

Reason #8: VBA Code Attempts to Activate Range on a Worksheet that is Not Active

Suppose you have a workbook with two worksheets: “Sheet1” and “Sheet2”. Currently, “Sheet2” is active.

The code below will result in the error message “Run-time error ‘1004’: Activate method of Range class failed” because it tries to activate a range on “Sheet1” that is inactive.

Or, better still, insert a line in the code that activates the target worksheet. In our example, we have inserted a line that activates “Sheet1” before range activation:

Dealing with Error 1004 Through Error Handling

Error handling allows you to gracefully handle errors that may occur during the execution of your code. 

To use error handling to handle a runtime error 1004 in VBA, you can use the ‘On Error’ statement.

Here’s an example of how to use error handling to handle error 1004:

Here’s how the code works:

  • ‘On Error Resume Next’: This statement turns on error handling, allowing VBA to continue executing code even if an error occurs.
  • The code that might cause the 1004 error is placed inside the error handling block.
  • After attempting the problematic operation, you check if ‘Err.Number’ equals 1004, indicating runtime error 1004.
  • If the error is 1004, you can display a user-friendly message using the ‘MsgBox’ function and exit the sub-routine.
  • ‘On Error GoTo 0’ is used to turn off error handling. This statement is optional but recommended to avoid unexpected error handling in subsequent code.

You can expand on this to handle other specific error numbers or to take different actions based on the nature of the error.

Remember, robust error handling involves not only notifying the user or the developer of an error but also, when possible, providing ways to recover from errors or ensuring that the application can continue running safely.

In this tutorial, we discussed eight common reasons for encountering runtime error 1004 in your code and provided solutions. We hope you found the tutorial helpful.

Other Excel VBA articles you may also like:

  • What is VBA in Excel?
  • Microsoft Excel Terminology (Glossary)
  • VBA Runtime Error 91
  • Using Application.EnableEvents in VBA in Excel
  • SetFocus in Excel VBA
  • Macro vs. VBA – What’s the Difference?
  • Count Rows using VBA in Excel
  • VBA to Remove Duplicates in Excel
  • Create New Workbook Using VBA in Excel
  • How to Change Cell Color Using VBA in Excel
  • VBA ByRef Argument Type Mismatch

' src=

Steve Scott

I am a huge fan of Microsoft Excel and love sharing my knowledge through articles and tutorials. I work as a business analyst and use Microsoft Excel extensively in my daily tasks. My aim is to help you unleash the full potential of Excel and become a data-slaying wizard yourself.

More Recovery Products

  • Partition Manager     Partition Master Personal disk manager   Partition Master Enterprise Business disk optimizer   Edition Comparison Partition Master Versions Comparison   Disk Copy Hard drive cloning utility Partition Master Free Partition Master Pro

Centralized Solutions

MSPs Service

Screen Capture

Video Toolkit

Audio Tools

Transfer Products

File Management

iOS Utilities

More Products

  • Support     Support Center Guides, License, Contact   Download Download installer   Chat Support Chat with a Technician   Pre-Sales Inquiry Chat with a Sales Rep   Premium Service Solve fast and more

EaseUS Data Recovery Wizard   11582 Reviews

How to Fix Runtime Error 1004 in Excel

This article aims to help you fix the error message Runtime Error 1004 when you run the Microsoft Visual Basic. Keep reading and check more details about how to fix Runtime error 1004 in Excel.

 Trustpilot Rating 4.7

 Secure Download

Table of Contents

author icon

  • Video Recovery
  • SD Card Recovery
  • Recycle Bin Recovery
  • Recover Data from USB
  • Recover Deleted Emails
  • Hard Drive Not Showing Up in Windows
  • Recover Unsaved Word Documents
  • Recover Deleted Files
  • Recover Files from Virus Infected Hard Drive
  • Best Free Photo Recovery Software
  • Recover Files from Formatted Hard Drive

Four ways to fix runtime error 1004 in Excel:

Microsoft Visual Basic for Applications (VBA) is developed to help users write programs for the Windows operating system. It runs as an internal programming language in Microsoft Office, such as Word, Excel, and PowerPoint.

Some users have reported that when running VBA in an Excel chart or trying to generate a Macro in Excel documents, an error message popped up saying: Runtime error 1004. And then they find themselves cannot access the Excel files . If you have the same encounter as these users, this post is the right place for you. You can find both the reasons and the corresponding solutions of this error code on this page.

How to Fix Excel Error 1004

Runtime Error Details

The error message contains more information than the error code 1004. Generally, follow the error code, you can see a brief description. The most repeated error messages are listed below:

  • Runtime error 1004: Application or object-defined error.
  • Runtime error 1004: Method Ranger of Object Worksheet failed.
  • Runtime error 1004: Copy Method of Worksheet Class failed.

The Reason Why You See Runtime Error 1004 in Excel

If you want to know how to fix runtime error 1004 in Excel properly, you need to understand what leads to this issue. The following are the most prominent reasons.

  • Macro Name Error

The Macro you are running is copying the original worksheet to a workbook with a defined name that you did not save and close before running the Macro.

  • File Conflict

When opening the VBA Excel file, it gets conflicted with other programs.

  • Too Many Legend Entries

The Excel chart contains more legend entries than space available to display the legend entries on the chart.

  • Excel File Corruption

Your .xls files got corrupted, infected, or damaged.

Although many reasons would cause this Excel error 1004 problem, luckily, some valid methods can help users re-access the files. Let's check them one by one.

Fix 1. Repair Corrupted Excel Files Due to Error 1004 

If all the above solutions can't help you out, then there is one possibility that the Excel file you want to open is damaged. To fix a damaged Excel file, you can rely on file repair software. EaseUS Fixo Document Repair is a great choice.

With this tool, click the "Repair" button and wait for it to fix all the corrupted documents for you.

  • Repair various corrupted files, including repairing Word, Excel, and PDF document 
  • Fix unreadable contents in Word efficiently
  • Repair corrupted PDF files, extract the text, comments, labels, graphics, etc. 
  • Compatible with Microsoft Office 2019, 2016, 2013, 2010, & previous versions.

Before you are going to fix runtime error 1004 in Excel, watch this video first. It provides you with more details on file repair.

  • 00:14 - Method 1. Insert to a new Word document
  • 00:38 - Method 2. Use open and repair
  • 00:55 - Method 3. Default settings
  • 01:30 - Method 4. EaseUS Fixo Document Repair

Download the software and follow the detailed steps below to fix corrupted Excel files.

Step 1. Download and launch Fixo on your PC or laptop. Choose "File Repair" to repair corrupted Office documents, including Word, Excel, PDF, and others. Click "Add Files" to select corrupted documents.

add files to repair documents with Fixo

Step 2. To repair multiple files at once, click the "Repair All" button. If you want to repair a single document, move your pointer to the target file and choose "Repair". You can also preview the documents by clicking the eye icon.

select documents to repair

Step 3. Click "Save" to save a selected document. Select "Save All" to save all the repaired files. Choose "View Repaired" to locate the repaired folder.

save repaired documents in Fixo

Fix 2. Delete the GWXL97.XLA Files to Fix Runtime Error 1004 in Excel

The easiest method to fix the Excel error 1004 is to find and delete the error file.

Step 1. Go to C:\Program Files\MS Office\Office\XLSTART.

Step 2. Find GWXL97.XLA file and delete it.

Step 3. Reopen your Excel file and check if the problem is solved.

Fix 3. Check the Trust Access to the VBA Project Object Model

Another solution you can try is to enable a VBA project trust option in Excel Trust Center. Follow the detailed steps and have a try.

Step 1. Open a blank Excel file and click "Files" on the upper left.

Step 2 . Click Option and go to Trust Center.

Enter Excel Option

Step 3. Find and enter the Trust Center Settings.

Enter Trust Center Settings

Step 4. Under Macro Settings, tick the option of "Trust access to the VBA project object model."

Trust Access to the VBA Project

Now you can check your Excel file.

Fix 4. Create Another Excel Template to Fix Runtime Error 1004 in Excel

This method could be a little bit complicated, but it's useful and worth trying.

Step 1. Please start a new Excel workbook and make sure there is only one worksheet in it.

Step 2. Format the workbook first and then put the data you need onto it.

Step 3. Tap File > Save As, first enter the file name, and click the unfold arrow in Save as Type column.

Excel Save As

Excel 2003: Choose Excel 97-2003 Template.

Excel 2007 or Later: Choose Excel Template.

Choose the Right Template

Step 4. Click "Save" to confirm.

Now you can insert it programmatically by using the following code: Add Type:=path\filename. The file name is the one you set when you create the new Excel template.

The Bottom Line

After reading, you must have a thorough understanding of how to fix Runtime error 1004. If you can make sure that the Excel file you want to open is valid, then the first three methods would help you out.

Once you got a damaged Excel file, a professional file recovery tool is a wiser choice. EaseUS Fixo is highly recommended by many users & IT professionals to help you repair Word, Excel, PowerPoint, and PDF files. 

Was This Page Helpful?

excel solver error 1004

Updated by Dany

Dany is an editor of EaseUS who lives and works in Chengdu, China. She focuses on writing articles about data recovery on Mac devices and PCs. She is devoted to improving her writing skills and enriching her professional knowledge. Dany also enjoys reading detective novels in her spare time.

Read full bio

excel solver error 1004

Written by Cedric 

Cedric Grantham is a senior editor and data recovery specialist of EaseUS. He mainly writes articles and how-to tips about data recovery on PC and Mac. He has handled 10,000+ data recovery cases and is good at data recovery of NTFS, FAT (FAT32 and ExFAT) file systems, and RAID structure reorganization.

 Product Reviews

EaseUS Data Recovery Wizard is a powerful system recovery software, designed to enable you to recover files you’ve deleted accidentally, potentially lost to malware or an entire hard drive partition.

EaseUS Data Recovery Wizard is the best we have seen. It's far from perfect, partly because today's advanced disk technology makes data-recovery more difficult than it was with the simpler technology of the past.

EaseUS Data Recovery Wizard Pro has a reputation as one of the best data recovery software programs on the market. It comes with a selection of advanced features, including partition recovery, formatted drive restoration, and corrupted file repair.

Related Articles

How to Delete Temp Files in Windows | 6 Tested Plans 

author icon

Where Do Permanently Deleted Photos Go on PC/iPhone/Android

author icon

How to Corrupt a PDF File so That It Can't Be Opened (Step-by-Step Guide)

author icon

How to Mount ISO File in Windows 10/11

excel solver error 1004

Copyright ©   EaseUS. All rights reserved.

  • Microsoft Office

How to Fix Run-Time Error 1004 in Excel?

User avatar

  • Facebook Opens a new window
  • Twitter Opens a new window
  • Reddit Opens a new window
  • LinkedIn Opens a new window

Author Priyal (Stellar Info Tech)

  • Microsoft Exchange |
  • Microsoft Office 365 |
  • Microsoft Office |
  • Data Recovery |
  • Microsoft SQL Server

The **Run-time error 1004** in Excel usually occurs when running macros or modifying ranges/cell values. It often occurs when there is an issue with the VBA code. It happens when there are too many legend entries in the MS Excel chart than the available space. Besides this, there are many other causes that may lead to this error. This article will discuss the possible causes behind the run-time error 1004 and the methods to fix the error.

**Causes of Excel Run-time Error 1004**

This error can occur when Microsoft Excel fails to read the VBA code you are trying to run in Excel. There could be many reasons behind this error. Some common reasons are: - [Mismatch datatypes]( https://www.stellarinfo.com/blog/resolve-excel-runtime-error-13/ ) in the VBA code. - The Excel file is corrupted. - Corrupted macros/charts. - Incorrect VBA code. - Trying to rename the worksheet with the name that already exists. - Invalid name range. - Trying to use VBA code to open an already opened worksheet. - Incorrect function or method usage. - The issue with Macro Settings. - You don’t have sufficient file permissions.

**Methods to Resolve Excel Run-Time Error 1004**

The error can occur when there are many legend entries in an Excel chart and the available space is limited. You can reposition the legend position using a custom legend layout and a smaller font size to reduce the legend text to fit more entries in available space. If the issue is not related to legend entries, then try the below methods to fix this error.

5 Steps total

Step 1: check the vba code.

The run-time error 1004 can occur if there are issues in the VBA code, such as incorrect or missing syntaxes, invalid name range, or missing parameters/functions/references. It can also occur if the macro contains incompatible functions or a wrong name of the object. You can open the VBA editor to check and fix such issues.

Step 2: Search and Delete GWXL97.XLA Files

Sometimes, the run-time error 1004 can occur due to incompatible add-ins files (.XLA) in Excel. All add-ins files are available in the Startup folder. You can find and delete the GWXL97.XLA add-ins files to fix the error.

Here are the steps: - Open the **Windows Explorer** window with Admin rights. - Follow the path C:\Programs Files\MSOffice\Office\XLSTART. - Search for the GWXL97.XLA file and then right-click on it. - Select **Delete**.

Step 3: Check the Macro Security Settings

Step Check the Macro Security Settings

You can encounter the run-time error 1004 if your macros are disabled in Excel’s Macro Security. You can try changing the settings to fix the issue.

Here are the steps to do so: - In Excel, go to the **Developer** tab and click **Macro Security**. - The Trust Center window is displayed. Select the **Enable all macros** option and click **OK**.

Step 4: Check the Excel File Permissions

Step Check the Excel File Permissions

You can also get the Excel runtime error 1004 while modifying the data in charts. Usually, this happens when you do not have permissions to modify the desired file. You can check and change the Excel file permissions.

Here are the steps: - First, locate the Excel file (in which you are getting the error) using Windows Explorer. - Right-click on the file and select **Properties**. - In the **File Properties** dialog box, click the **Security** tab and then click on the **Edit** option. - In the **File Permissions** dialog box, select the **Add** button. - In **Select Users or Groups**, click the **Advanced** option. - Click **Find Now**. In the result field, a list of all users and groups will get displayed. - Click on the **Everyone group** from the list and click **OK**. - Under **‘Enter the object names to select’**, you will see **Everyone**. Click **OK**. - Next, click **Everyone** and select all checkboxes that appears below the **Allow** option. Click **Apply** and **OK**.

Step 5: Repair the Workbook

Step Repair the Workbook

The error may also occur due to corrupted or damaged Excel file. In such a case, you can repair the file by using the built-in utility in Excel - Open and Repair.

Here are the steps to use this tool: - In the **Excel** application, click the **File** option and then select **Open**. - Select **Browse** to choose the desired worksheet. - The **Open** dialog box is displayed. - Select the damaged Excel file. - Click on the arrow that appears next to the **Open** option. - Click the **Open and Repair** option. - In the dialog box that appears, click on the **Repair** option to recover as much data as possible. - After the repair process is complete, a message appears on the screen. Click **Close**.

If the [Open and Repair utility does not solve the issue]( https://www.stellarinfo.com/blog/ms-excel-open-and-repair-option-is-not-working/ ), you can try other Excel repair tools to repair your Excel file. **Stellar Repair for Excel** is one such dedicated [Excel repair tool]( https://www.stellarinfo.com/repair-excel-file.php ) that can repair severely corrupted Excel files. It helps recover macros, charts, formulas, and other components from the corrupted or damaged Excel file (.xls, .xlsx, .xltm, .xltx, and .xlsm).

The runtime error 1004 in Excel can occur due to incorrect object references, invalid methods, or various other VBA code issues. You can cross-check the queries and code you are trying to run in macros and check the macro’s security settings to fix the error. If the error occurred due to a corrupted Excel file or damaged file components, try **Stellar Repair for Excel** to repair the Excel workbook. The tool preserves the file’s data integrity while repairing. You can download the tool’s demo version to check the recoverable objects.

  • How to Fix Runtime Error 1004 in Excel Opens a new window
  • Stellar Repair for Excel Opens a new window

User avatar

Experience the effortless resolution of all MS Excel errors with the user-friendly Kernel for Excel Repair tool. It's the ideal solution even for non-technical users. For additional information about the software, please visit https://www.nucleustechnologies.com/repair-excel-file.php

excel solver error 1004

  • Help Center /

Fixing Run Time Error 1004 in Excel - Troubleshooting Guide

Runtime Error 1004 is a common issue that many Excel users encounter, and it can disrupt your workflow. You can troubleshoot and resolve the error by following the steps outlined in this guide.

Stay tuned as we dive into the details of fixing Runtime Error 1004 in Excel, empowering you to overcome this obstacle and continue working efficiently. Let's start resolving this error and restoring the smooth functioning of your Excel application.

Table of Contents

Reasons why you see runtime error 1004 in excel, fix 1: delete the gwxl97.xla files to fix runtime error 1004 in excel, fix 2: check the trust access to the vba project object model, fix 3: create another excel template to fix runtime error 1004 in excel, final thoughts.

Runtime Error 1004 in Excel can occur for various reasons, and understanding these causes is crucial to resolve the issue effectively. Here are the most common reasons behind this error:

  • Macro Name Error : The error may occur if you run a macro that copies the original worksheet to a workbook with an undefined name. Before running the macro, save and close the workbook with the desired name.
  • File Conflict : When opening an Excel file with VBA, conflicts can arise if another program uses or locks the file. Ensure that no other programs access the file before opening it with VBA.
  • Too Many Legend Entries : This error can occur in Excel charts with more legend entries than the available space to display them. Reduce the number of legend entries or adjust the chart layout to accommodate all entries.
  • Excel File Corruption : If your Excel file (.xls) is corrupted, infected, or damaged, it can lead to Runtime Error 1004. In such cases, you may need to repair or recover the file using Excel's built-in repair options or third-party file recovery tools.

To fix Runtime Error 1004 in Excel, consider the following methods:

  • Ensure the macro references valid worksheets and workbooks.
  • Close any conflicting programs before opening Excel files with VBA.
  • Remove excess legend entries or modify the chart layout.
  • Repair or recover corrupted Excel files using appropriate tools.

By addressing these potential causes and following the suggested methods, you can effectively resolve Runtime Error 1004 and regain access to your Excel files.

One of the simplest methods to resolve Runtime Error 1004 in Excel is deleting the GWXL97.XLA file. Follow these steps to apply this fix:

  • Locate the GWXL97.XLA file : Navigate to the directory C:\Program Files\MS Office\Office\XLSTART. This is where the file is typically located.
  • Delete the GWXL97.XLA file : Once you have found the file, right-click on it and select "Delete" from the context menu. Confirm the deletion when prompted.
  • Reopen Excel : After deleting the file, reopen your Excel application and try running your worksheet or macro again.

By removing the GWXL97.XLA file, you eliminate any potential conflicts or issues associated with it, which can help resolve Runtime Error 1004. However, it's important to note that this fix addresses issues related to this file. Further troubleshooting may be required if the error persists or if you encounter other error messages.

Please note that the file path mentioned (C:\Program Files\MS Office\Office\XLSTART) may vary depending on the version and installation location of your Microsoft Office. Adjust the path accordingly if necessary.

Enabling the "Trust access to the VBA project object model" option in Excel Trust Center can help resolve Runtime Error 1004. Follow these steps to apply this fix:

  • Open Excel and create a blank file : Launch Excel and open a new, empty workbook.
  • Access Excel Options : Click on the "File" tab in the upper left corner of the Excel window.

Navigate to Trust Center

  • Confirm and apply changes : Click "OK" to save the changes made in the Trust Center dialog box.

This option allows access to the VBA project object model, which can help resolve Runtime Error 1004 in Excel. Reopen your Excel file once the changes are applied and check if the error is resolved.

Creating a new Excel template can be an effective solution to resolve Runtime Error 1004. Follow these steps to implement this fix:

  • Start a new Excel workbook : Open Excel and create a new workbook. Make sure there is only one worksheet in the workbook.
  • Format and populate the workbook : Format the workbook according to your needs and enter the required data.

Save the workbook as a template

  • For Excel 2003: Choose "Excel 97-2003 Template."
  • For Excel 2007 or later: Choose "Excel Template."
  • Confirm and save the template: Click "Save" to confirm and save the new Excel template.

You can programmatically insert the template using the following code: Add Type:=path\filename, where "filename" is the name you assigned when creating the new Excel template.

What does run-time error 1004 mean?

Run-time error 1004 is a common error in Excel that occurs when a macro or VBA code encounters an issue while running, often due to problems with objects, ranges, or data.

What is Excel error Microsoft Visual Basic run-time Error 1004?

Microsoft Visual Basic run-time Error 1004 in Excel is a specific instance of a run-time error that occurs when VBA code encounters an issue while executing, typically related to incorrect object references, invalid data, or improper range operations.

What is run-time error 1004 VBA file not found?

Run-time error 1004 "File Not Found" in VBA typically occurs when attempting to access a file that does not exist or providing an incorrect file path.

How do you fix runtime error 1004 application-defined or object-defined error?

To fix the runtime error 1004 "application-defined or object-defined error" in Excel, you can try resolving issues with object references, ensuring proper syntax in your VBA code, verifying data ranges, and debugging your code step by step.

How do I fix runtime error in Excel VBA?

To fix a runtime error in Excel VBA, you can use various approaches such as verifying object references, checking for valid data and range operations, debugging code, using error handling techniques like On Error statements and ensuring compatibility with different Excel versions.

In conclusion, fixing Run Time Error 1004 in Excel requires a systematic approach and an understanding of the underlying causes. Identifying the specific error message and its context is crucial to apply the appropriate solution. 

Common fixes include deleting specific files, enabling trusted access to the VBA project object model, creating new Excel templates, and repairing corrupted files. Additionally, thorough debugging and error-handling techniques can help pinpoint and resolve issues in VBA code. 

It is important to remember that each situation may be unique, so analyzing the error and applying the most relevant solution carefully is essential. With patience and persistence, you can overcome Run Time Error 1004 and ensure smooth operation in Excel.

One more thing

If you have a second, please share this article on your socials; someone else may benefit too. 

Subscribe to our newsletter and be the first to read our future articles, reviews, and blog post right in your email inbox. We also offer deals, promotions, and updates on our products and share them via email. You won’t miss one.

Related articles 

» How to Fix Excel Sharing Violation Error » Microsoft Excel is Attempting to Recover Your Information - How to Fix » Windows 10/11 Taskbar Disappeared? Here's How to Fix It

excel solver error 1004

Top Contributors in Excel: HansV MVP  -  Andreas Killer  -  Ashish Mathur  -  Jim_ Gordon  -  Rory Archibald   ✅

February 13, 2024

Top Contributors in Excel:

HansV MVP  -  Andreas Killer  -  Ashish Mathur  -  Jim_ Gordon  -  Rory Archibald   ✅

  • Search the community and support articles
  • Microsoft 365 and Office
  • Search Community member

Ask a new question

i keep getting a runtime error 1004 application defined or object defined error and No i dont use VBA just excel using vlookup and if error formulas how do i solve it

excel solver error 1004

Report abuse

Replies (2) .

Yea So

How to fix Excel error 1004 – Business Tech Planet

Was this reply helpful? Yes No

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

Thanks for your feedback.

Inactive profile

Question Info

  • Norsk Bokmål
  • Ελληνικά
  • Русский
  • עברית
  • العربية
  • ไทย
  • 한국어
  • 中文(简体)
  • 中文(繁體)
  • 日本語
  • Office Document Solutions
  • Photo/Video/Audio/Camera Solutions
  • Email-Related Solutions
  • Windows Computer Solutions
  • Mac Computer Solutions
  • Linux Solutions
  • Hard Drive Solutions
  • SD Card Solutions
  • USB Drive Solutions
  • NAS Disk Solutions
  • Data Backup Solutions
  • File Format
  • File System
  • Storage Media
  • Disk Parition
  • DOWNLOAD DOWNLOAD
  • Buy Now Buy Now

recoverit

File Recovery

  • Recovers deleted or lost files effectively, safely and completely.
  • Supports data recovery from 500+ data loss scenarios, including computer crash, partition loss, accidental human error, etc.
  • Supports 1000+ file formats recovery with a high success rate and without any quality loss.

file recovery

How to Fix Excel File Runtime Error 1004

Wondershare Recoverit Authors

Jan 15, 2024 • Filed to: Recover Files • Proven solutions

Microsoft Excel is the most popular data manipulation application used by millions of users across the globe. This application can be used by both personal and business-related data storage and display. But a common " runtime error 1004 " might be distracting as it stops the application by affecting MS Excel or XLS/XLSX files.

This blog provides the list of common errors found when an excel file is running and also the best methods that can resolve the  excel runtime error 1004 . This error can cause very serious damage to your excel file and might lead to a program crash. Let us go through the article and get rid of the unexpected and unwanted  runtime error 1004.

Part 1: Common Excel Run-time 1004 Errors and Issues

Below is the list of common errors displayed related to  excel runtime error 1004 :

  • "VB: run-time error 1004": Application or Object-defined error.
  • "Select method of Range class failed": Excel VBA Runtime error 1004.
  • "Run-time error 1004"- Excel macro.
  • "Runtime error 1004" This error occurs when method open of object workbooks failed
  • "Run time error 1004" This error occurs when Method 'Ranger' of Object' Worksheet' Failed
  • "Save As VBA run time Error 1004" Application or object-defined error.

How to recover unsaved or deleted Excel files without data loss.

Part 2: How to Fix Excel Runtime Error 1004

Fix 1: uninstall microsoft work.

Excel runtime error 1004 is the error that occurs when the excel file is corrupted. This can be resolved by Uninstalling Microsoft Work by following the below steps:

  • Before uninstalling Microsoft work, you have to stop all the running programs by pressing "ctrl+alt+delete" and opening "Task Manager".
  • Then go to "Control panel" from the "Start" menu or by opening "My  Computer".

click-on-control-panel

  • Go to "Programs"->" Uninstall a program".
  • Search for "Microsoft Works" and right-click on it and select "Uninstall".

uninstall-microsoft-works

Fix 2: Delete The "GWXL97.XLA" File

If the above method doesn't resolve the error 1004, you can delete the "GWXL97.XLA" file by following the below steps:

  • Go to "My Computer".
  • Go to the following directory "C:\Program Files\MSOffice\Office\XLSTART".

gwxl97-1

  • In this location, right-click on "GWXL97.XLA" file.
  • Click "Delete".

gwxl97-2

  • Now open Excel and check whether it is opening or not.

Fix 3: Create New Excel Template

If you are not able to open the excel file after deleting the "GWXL97.XLA" file, then follow the simple process of creating a new excel template by following the below steps:

Step 1 –  Launch the excel application.

Step 2 –  Click on the "Office" symbol and click on "Save As".

new-excel-template-1

Step 3 –  On the side menu, select "Excel Workbook".

Step 4 –  From the drop-down menu of "Save as Type", select "Excel template".

Step 5 –  Select the corrupted excel file and click on "Save".

new-excel-template-2

Part 3: Free Download Excel File Repair Tool

If MS Excel is issuing the excel file runtime error 1004 when you are trying to open your excel files then there is surely a problem with it. You can fix excel file runtime error 1004 by using a good excel repair tool. However, finding such a tool isn't that easy. There aren't many excel repair tools that can fix this error message.  Stellar Phoenix Excel Repair  is among the few repair tools that can fix Excel file runtime error 1004.

Microsoft Excel Repair Tool

Microsoft Excel Repair Tool

  • Recovers all kinds of data stored in damaged excel files such as tables, charts, formulas, comments, images, etc.
  • Restore all of your corrupted excel files to their original standing.
  • Preview the repaired excel file in real-time, see how much of the file has been recovered as it is being repaired.
  • All kinds of MS office corruption errors (for XLS and XLSX files only) can be handled with this tool.
  • This excel file repair tool can be used on both Windows and Mac platforms to  repair corrupt excel file .
  • This excel file repair tool can repair damaged files of all versions from 2000 to 2016 that includes 2000, 2003, 2007, 2010, 2013, etc.

Stellar Phoenix Excel Repair is an efficient excel repair tool. It can fix excel file runtime error 1004 safely and effectively within a few seconds.

Part 4: How to Fix Excel File Runtime Error 1004

Here is a step-by-step instruction guide that has been generated to cater to the needs of the users of Stellar Phoenix Excel Repair. It helps them in learning  how to fix excel file  runtime error 1004 with this wonderful excel repair tool.

Step 1  Clicking any one of the following buttons, 'Search Files', 'Select Folder', or 'Select File'. To search for the corrupted excel file from the system.

fix excel file runtime error 1004 step 1

Step 2  All corrupt Excel file display in the result section, by clicking the 'Scan' button to start the repairing process.

fix excel file runtime error 1004 step 2

Step 3  Double-clicking the file to previewing of the corrupted excel file

fix excel file runtime error 1004 step 3

Step 4  The last guide is concerned with the repairing and saving of the corrupted excel file

fix excel file runtime error 1004 step 4

Some useful tips:

If you are fed up with the constant corruption of your excel files then you must try to find a permanent solution for this problem. The following tips might come in handy in this regard.

  • Invest in a non-compromising anti-virus suite. Make sure that it is capable of dealing with not just viruses but also malicious software of all kinds.
  • Ensure that your local hard disks are in perfect health and have no bad sectors present on them.
  • When trying to transfer excel files from your USB to hard disk and vice versa, make sure that everything remains connected until the transfer process has finished.

The Bottom Line

As excel application has all the important data related to your business or company, it will be very annoying if it does not open. This article will help you to resolve the error and open the corrupt excel file. The manual and automatic solutions or methods are given in this article will help you in resolving the "runtime error 1004". Initially try to uninstall Microsoft works, if it doesn't work, go and delete the GWXL97.XLA file from your computer. If these two don't provide you a solution then you can open the excel workbook as a template and start working on it.

People Also Ask

How do I fix runtime error 1004 in Excel?

To resolve the runtime error 1004 in excel, you need to follow the simple process of opening the excel workbook as a template. For this follow the below steps:

  • Launch Microsoft Excel on your computer.
  • Click on Office symbol and click" Save as".
  • In the "Save as type" drop-down, select "Excel template" and click "Save".

Once the template has been created, insert the data using the following line of code:

"Sheets.Add Type:=path\filename".

How do I fix Visual Basic runtime error 1004?

To resolve the Visual Basic runtime error 1004, trusted access to Visual Basic for Applications has to be given following the below steps:

  • Launch Microsoft Excel and open the blank workbook in excel.
  • Click on Office symbol, click "options".
  • Under options, click "Trust Center".
  • In "Macro settings", check whether "Trust access to the VBA project object model " is checked or not.

How do I fix Visual Basic error in Excel?

To fix the Visual Basic error in excel, you need to follow some manual and automatic methods which include:

  • Uninstalling Microsoft works.
  • Create and import all the excel files into a new excel template.
  • Try force stop of excel application and launch it again.
  • Delete the files that might affect the Excel worksheet

How do I fix a runtime error?

To fix a runtime error in excel, you can use the methods or solutions given in the above blog. In addition to this, it is recommended to scan your computer for any viruses or malware as they can be the main reason for file corruption. Use the best antivirus to scan and remove the viruses from the computer.

Recover & Repair Files

  • Recover Lost PPT Files
  • Files Unreadable Errors
  • Recover Unsaved PPT Files on Mac
  • Repair Excel File Online
  • Excel File Corrupted?
  • Excel Cannot Open File
  • Rescue Damaged Excel
  • Restore Corrupted Files
  • Recover a Folder
  • 0 Byte Files Solution
  • Undeleted Recycle Bin
  • Recover Folder on Windows
  • Retrieve Lost Files
  • Shift Deleted Files
  • Delete File Completely

You Might Also Like

Article

Other popular Articles From Wondershare

Recoverit author

staff Editor

Home

  • 0 + Awards Received
  • 0 % Recovery Rate
  • 30 Years of Excellence

Recovers lost or deleted Office documents, emails, presentations & multimedia files.

  • Professional

Recovers deleted files, photos, videos etc. on Mac.

Recover photos, videos, & audio files from all cameras and storage on Windows or Mac.

iPhone Data Recovery

Recover deleted photos, videos, contacts, messages etc. directly from iPhone & iPad.

Video Repair

Repair multiple corrupt videos in one go. Supports MP4, MOV & other formats.

Photo Repair

Repair multiple corrupt photos in one go. Supports JPEG & other formats.

  • Exchange Repair Repair corrupt EDB file & export mailboxes to Live Exchange or Office 365
  • Outlook PST Repair Repair corrupt PST & recover all mailbox items including deleted emails & contacts
  • OLM Repair Repair Outlook for Mac (OLM) 2011 & 2016 backup files & recover all mailbox items
  • Exchange Toolkit Repair EDB & Exchange backup file to restore mailboxes, convert OST to PST, & convert EDB to PST
  • Active Directory Repair Repair corrupt Active Directory database (Ntds.dit file) & extract all objects in original form
  • EDB to PST Convert online & offline EDB file & extract all mailbox items including Public Folders in PST
  • OST to PST Convert inaccessible OST file & extract all mailbox items including deleted emails in PST
  • NSF to PST Convert IBM Notes NSF file & export all mailbox items including emails & attachments to PST
  • MBOX to PST Convert MBOX file of Thunderbird, Entourage & other clients, & export mailbox data to PST
  • OLM to PST Convert Outlook for Mac Data File (OLM) & export all mailbox data to PST in original form
  • GroupWise to PST Convert GroupWise mail & export all mailbox items - emails, attachments, etc. - to PST
  • EML to PST Convert Windows Live Mail (EML) file & export mailbox data - emails, attachments, etc. - to PST
  • Office 365 to PST Connect to Office 365 account & export mailbox data to PST and various other formats
  • Migrator for Office 365 Quickly migrate Outlook data files(OST/PST) directly to Office 365 or Live Exchange
  • SQL Repair Repair corrupt .mdf & .ndf files and recover all database components in original form
  • Access Repair Repair corrupt .ACCDB and .MDB files & recover all records & objects in a new database
  • QuickBooks Repair Repair corrupt QuickBooks® data file & recover all file components in original form
  • MySQL Repair Repair MyISAM & InnoDB tables and recover all objects - keys, views, tables, triggers, etc.
  • Excel Repair Repair corrupt Excel (.XLS & .XLSX) files and recover tables, charts, chart sheet, etc.
  • BKF Repair Repair corrupt backup (BKF, ZIP, VHDX and .FD) files and restore complete data
  • Database Converter Interconvert MS SQL, MySQL, SQLite, and SQL Anywhere database files
  • PowerPoint Repair Repair corrupt PPT files and restore tables, header, footer, & charts, etc. like new
  • File Repair Toolkit Repair corrupt Excel, PowerPoint, Word & PDF files & restore data to original form
  • Data Recovery Recover lost or deleted data from HDD, SSD, external USB drive, RAID & more.
  • Tape Data Recovery Retrives data from all types and capacities of tape drives including LTO 1, LTO 2, LTO 3, & others.
  • Virtual Machine Recovery Recover documents, multimedia files, and database files from any virtual machine
  • File Erasure Permanently wipe files and folders, and erase traces of apps and Internet activity.
  • Mobile Erasure Certified and permanent data erasure software for iPhones, iPads, & Android devices
  • Drive Erasure Certified and permanent data erasure software for HDD, SSD, & other storage media
  • Exchange Toolkit 5-in-1 software toolkit to recover Exchange database, convert EDB to PST, convert OST to PST, restore Exchange backup, and reset Windows Server password.
  • Outlook Toolkit Comprehensive software suite to repair PST files, merge PST files, eliminate duplicate emails, compact PST files, and recover lost or forgotten Outlook passwords.
  • File Repair Toolkit Powerful file repair utility to fix corrupt Word, PowerPoint, and Excel documents created in Microsoft Office. It also repairs corrupt PDF files and recovers all objects.
  • MS SQL Toolkit 5-in-1 software toolkit to repair corrupt SQL database, restore database from corrupt backup, reset database password, analyze SQL logs, & interconvert databases.
  • Data Recovery Toolkit Software helps to recovers deleted data from Windows, Mac and Linux storage devices. Also supports recovery from RAIDs & Virtual Drives.
  • MySQL Toolkit 3-in-1 software toolkit to repair Corrupt Mysql, MariaDB & Analyze logs, and Interconvert Databases.
  • Email Forensic Advanced email forensic solution for cyber experts to audit, analyze, or investigate emails & gather evidences.
  • Log Analyzer for MySQL Analyze forensic details of MySQL server database log files such as Redo, General Query, and Binary Log.
  • Exchange Auditor Exchange Server monitoring solution to automate audits, scans and generate reports ìn real-time.
  • Log Analyzer for MS SQL Track & analyze MS SQL Server database transactions log files.
  • Our Partners
  • Lab Services

Microphone Icon Android

Trending Searches

Data Recovery

Photo Recovery

File Erasure Software

Exchange Repair

Raid Recovery

MS SQL Repair

How to Fix Excel Run-Time Error 1004?

Summary: Run-time errors are windows-specific issues that occur while the program is running. This blog will teach you how to fix Excel run-time error 1004. In addition, you’ll learn about an Excel repair tool that can help fix the error 1004 if it occurs due to corruption in Excel files.

Free Download for Windows

Why This Error Occurs?

Ways to fix excel run-time error 1004.

VBA (Microsoft Visual Basic for Application) is an internal programming language in Microsoft Excel. Sometimes, when users try to run VBA or generate a Macro in Excel, the Run-time error 1004 may occur. This error may occur due to the presence of more legend entries in the chart, file conflict, incorrect Macro name, and corrupt Excel files. In this blog, we have discussed the reasons and shared some solutions to resolve run-time error 1004.

The run time error 1004 usually occurs when you run a VBA macro with the Legend Entries method to modify the legend entries in the MS Excel chart. It happens when the chart contains more legend entries than the available space, macro name conflicts, corrupt Excel files, or data-types mismatch in the VBA code.

Try the below workarounds to fix Excel run-time error 1004:

Create a Macro to Reduce Chart Legend Font Size

Sometimes, Excel throws the run-time error when you try to run VBA macro to change the legend entries in a Microsoft Excel chart. This error usually occurs when Microsoft Excel truncates the legend entries because of the more legend entries and less space availability. To fix this, try to create a macro that shrinks/minimize the font size of the Excel chart legend text before the VBA macro, and then restore the font size of the chart legend. Here is the macro code:

Uninstall Microsoft Work

You may encounter a run-time error 1004 in Excel version 2009 or older versions due to conflicts between Microsoft works and Microsoft Excel. This error usually occurs if your system has both Microsoft Office and Microsoft Works. Uninstalling one of them will fix the issue. Try the below steps to uninstall Microsoft Work:

  • First, open the Task Manager using the shortcut CTRL + ALT + DEL altogether
  • The Task Manager window is displayed.
  • Click the Process tab, right-click on each program you want to close, and then click End Task.
  • Stop all the running programs.
  • Open the Run window and type appwiz.cpl to open the Programs and Feature window.
  • Search for Microsoft Works and click Uninstall .

Try Deleting GWXL97.Xla File

The Add-ins files with .xla extension in MS-EXCEL is used to provide additional functionality to Excel spreadsheets. Sometimes, deleting the GWXL97.XLA file fixes the run-time error. Here are the steps to delete this file:

  • Make sure you have an Admins rights , open the Windows Explorer
  • Follow the Path C:\Programs Files\MSOffice\Office\XLSTART.
  • Find and right-click on the GWXL97.XLA file
  • Click Delete .

Change Trust Center Settings

Sometimes, run-time errors might arise because of incorrect security settings. The Trust Center settings help you find the Privacy and security settings for Microsoft Excel. Follow the below steps to change the Trust center settings :

  • Open Microsoft Excel.
  • Go to File > Options.
  • The Excel options window is displayed.
  • Choose Trust Center , and click Trust Center Settings .
  • Tap on the Macro Settings tab, and select Trust access to the VBA project object model.

Run Open and Repair Tool

The Runtime error also arises when MS Excel detects a corrupted worksheet. It automatically begins the File recovery mode and starts repairing it. However, if the Recovery mode fails to start, use the Open and Repair tool with the below steps:

  • Click  File > Open .
  • Click the location and folder with a corrupted workbook.
  • In the  Open  dialog box, choose the corrupted workbook.
  • Click the arrow next to the  Open  tab, and go to the  Open and Repair  tab. 
  • Click  Repair .

You can also opt for Stellar Repair for Excel if the Microsoft Excel’s built-in tool cannot fix the error.

Use Stellar Repair for Excel

Stellar Repair for Excel is a professional software for repairing damage. xls, .xlsx, .xltm, .xltx, and .xlsm files and recovering all its objects. Here are the steps to fix the error using this tool:

  • First, download , install , and run  Stellar Repair for Excel .
  • Click the  Browse  tab on the interface window to choose the corrupted Excel file you need to repair.
  • Click  Scan . You will see the scan progress in the scanning window.
  • Click  OK .
  • The tool can let you preview all the recoverable Excel file components including tables, pivot tables, charts, formulas, etc.
  • Click  Save  to save the repaired file. 
  • A  Save File dialog box will appear with the below two options:
  • Default location
  • New location
  • Choose a suitable option. 
  • Click the  Save  option to repair the Excel file that you have chosen.
  • Once the repair is complete, it will display a message “ File repaired successfully .”

Now you know the Excel run-time error 1004, its cause, and solutions. Follow the workarounds discussed in the blog to rectify the error quickly. However, Stellar Repair for Excel makes your task of removing run-time errors easy. It’s a powerful software to fix all the issues with Excel files. Also, it helps in extracting data from the damaged file and saves it to a new Excel workbook.

About The Author

excel solver error 1004

Monika Dadool is a Technical content writer at Stellar who writes about QuickBooks, Sage50, MySQL Database, Active Directory, e-mail recovery, Microsoft365, Pattern Recognition, and Machine learning. She loves researching, exploring new technology, and Developing engaging technical blogs that help organizations or Database Administrators fix multiple issues. When she isn’t creating content, she is busy on social media platforms, watching web series, reading books, and searching for food recipes.

Related Posts

How to fix the “microsoft excel cannot access the file” error, [fixed]: file format and extension of [filename] don’t match. the file could be corrupted or unsafe, filter not working error in excel [fix 2024], free trial for 60 days.

WHY STELLAR ® IS GLOBAL LEADER

WHY STELLAR ® IS GLOBAL LEADER

Why Choose Stellar?

Years of Excellence

R&D Engineers

Awards Received

Technology You Can Trust A Brand Present Across The Globe

This website uses cookies in order to provide you with the best possible experience and to monitor and improve the performance of the site in accordance with our cookie policy .

Excel Help Forum

  • Forgotten Your Password?

Username

  • Mark Forums Read
  • Quick Links :
  • What's New?
  • Members List

Forum Rules

  • Commercial Services
  • Advanced Search

Home

  • Microsoft Office Application Help - Excel Help forum
  • Excel Programming / VBA / Macros

Run time error 1004 SOLVER

Thread tools.

  • Show Printable Version
  • Subscribe to this Thread…

Rate This Thread

  • Current Rating
  • ‎ Excellent
  • ‎ Average
  • ‎ Terrible

excel solver error 1004

Hey, I have a macro in the last of my spreadsheets which just won't work. It's a macro which supposedly should be able to solve the Max DB by changing price(pris). The name of the spreadsheet is "Samlet Uddata". The button is just named Solver so you know which one I mean. The data in the belonging cells is from the spreadsheet beregningsark opg. 3. The object is to maximize profit but the macro won't do it. Any suggestions as to what to do? I have attatched the spreadsheet. // Peter

Attached Files

Last edited by pede; 06-18-2013 at 12:25 PM .

Alf is offline

Re: Run time error 1004 SOLVER

Since the macro button is assigned to macro1 that only contains the command Please Login or Register to view this content. new Clipboard(".copy2clipboard",{target:function(a){for(;a ? a.getAttribute?a.getAttribute?!/bbcode_description/.test(a.getAttribute("class")):null:null:null;)a=a.parentNode;for(var b=a.nextElementSibling;b?!b.classList.contains("bbcode_code"):null;)b=b.nextElementSibling;return b}}); and no solver setting i.e. "Target cell", value of "Target cell", cells to change and Solver model you get the "Run time 1004" error. If you set up the macro like the Solver1 macro it will work. Alf Ps Even if you are posting in an non Danish forum macro names like Solverpik and Solverlorteluder can be understood by some members and will give offence and you may be banned by forum admin.
The problem is that I need to hide the spreadsheet which is called beregningsark opg. 3, and still be able to use the solver button in the Samlet Uddata. If I set up my macro like solver 1 it doesn't work when I hide beregningsark opg. 3. I have given it a new try and this is the result: IT og Øko eksamen(Færdig) (1) wubi.xlsm
hide the spreadsheet which is called beregningsark opg. 3, and still be able to use the solver button in the Samlet Uddata First of all, the way solver is set up this will not work as you found out. Extract from the solver home page: By Changing Cells must be on the active sheet. A limitation of the Solver is that all of the decision variables (adjustable or changing cells) in the By Changing Cells edit box must be cells on the active sheet. (This limitation makes the Solver considerably faster than if adjustable cells were allowed to be on any sheet.) You should re-design your Solver model so that all decision variables are on one sheet, and try again. What you could do is writing a macro that starts by "freezing" the screen using Please Login or Register to view this content. new Clipboard(".copy2clipboard",{target:function(a){for(;a ? a.getAttribute?a.getAttribute?!/bbcode_description/.test(a.getAttribute("class")):null:null:null;)a=a.parentNode;for(var b=a.nextElementSibling;b?!b.classList.contains("bbcode_code"):null;)b=b.nextElementSibling;return b}}); then the macro should activate the hidden sheet and run solver using the command Please Login or Register to view this content. new Clipboard(".copy2clipboard",{target:function(a){for(;a ? a.getAttribute?a.getAttribute?!/bbcode_description/.test(a.getAttribute("class")):null:null:null;)a=a.parentNode;for(var b=a.nextElementSibling;b?!b.classList.contains("bbcode_code"):null;)b=b.nextElementSibling;return b}}); then copy this result to another sheet and hide sheet " beregningsark opg. 3" and finally "un freeze" the screen with command Please Login or Register to view this content. new Clipboard(".copy2clipboard",{target:function(a){for(;a ? a.getAttribute?a.getAttribute?!/bbcode_description/.test(a.getAttribute("class")):null:null:null;)a=a.parentNode;for(var b=a.nextElementSibling;b?!b.classList.contains("bbcode_code"):null;)b=b.nextElementSibling;return b}}); Alf

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  • BB code is On
  • Smilies are On
  • [IMG] code is Off
  • HTML code is Off
  • Trackbacks are Off
  • Pingbacks are Off
  • Refbacks are Off
  • ExcelForum.com

MrExcel Message Board

  • Search forums
  • Board Rules

Follow along with the video below to see how to install our site as a web app on your home screen.

Note: This feature may not be available in some browsers.

  • If you would like to post, please check out the MrExcel Message Board FAQ and register here . If you forgot your password, you can reset your password .
  • Question Forums
  • Excel Questions

"Run-Time error '1004' How to solve this problem

  • Thread starter Willow350
  • Start date Jan 20, 2016
  • Jan 20, 2016

I have workbook which will be used by others and I have protected the workbook and only allow certian cells of the workbook to be changed if the user has the right password to be able to get into the workbook and do changes. In this workbook I have vb running a code that records information in the tab sheet named (log) of every time a user accesses this workbook and edits or adds changes to it a records the information on the tab (Log). When I have each sheet protected the code does not run and I keep receiveing this message "Run-Time error '1004' The cell or chart you are trying to change is protect and therefore read-only. When I unprotect the tab sheet named (Log) only and keep the other sheets protected the code then runs and it works. I need to have the tab sheet named (Log) protected how do I accomplish this and still be able to run the code?. I could use some help if any one other there can help me with this problem I would be greately appreciate it.  

Excel Facts

Eric W

MrExcel MVP

You need to unprotect the sheet at the start of your macro, then reprotect it when it finishes. Code: ActiveSheet.Protect Password:="password", DrawingObjects:=True, Contents:=True, Scenarios:=True ActiveSheet.Unprotect Password:="password"  

Andrew Poulsom

Andrew Poulsom

In your code you can Unprotect the worksheet, record the information then Protect it again.  

Thank you, I really appreciate that you replied back so quickly. Since this workbook will be accessed and used by others I can't Unprotect the worksheet, record the information then Protect it again. This workbook will be on a network drive made available for users to access it and by unportecting the worksheet everytime that means users would have to have the password to unprotect the workbook which I can not allow that.  

Well-known Member

what about doing what the others said but locking the vba project?  

Thank! Thats a great idea and I will try that. So if I protect the vba project and unprotect the sheet tab (log) this means that users can change the data in the tab (log) and I was hoping that could not be done I need to record every entry that is made to that workbook. I am still going to do your suggestion but hoping that there is still a way to not allow others to change the tab (log).  

whatever you are doing to the table, it requires the sheet be unlocked so no way around it. just only unlock your sheet for the lines of code that require it... if you minimize the time it is unlocked then it will be harder for someone to interrupt the macro and then be able to manipulate an unlocked sheet. If the sheet is unlocked for a split second it is going to be very difficult to break the security, not to mention they would need to know exactly what your macro was even doing.  

There is another option. The protect command has an option: UserInterfaceOnly. If you use this, then your macros can change the sheet, but the user can't. You do have to set it up when the workbook opens though. Here's a link to describe it: Sheet Protect (User Interface only) using VBA | ExcelExperts.com  

Hi Eric. I added the above code that you suggested at the start of my code and at end of the code. Now I am getting the error code: "Complie error: Invalid outside procedure" and my passoword is highligted. What am I doing wrong? Option Explicit Sheet("Log").Protect Password:="Willow123", DrawingObjects:=True, Contents:=True, Scenarios:=True Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range) Dim LR As Long If Sh.name = "Log" Then Exit Sub Application.EnableEvents = False With Sheets("Log") LR = .Range("A" & rows.Count).End(xlUp).row .Range("A" & LR + 1).Value = Now .Range("B" & LR + 1).Value = Sh.name .Range("C" & LR + 1).Value = Target.Address(False, False) .Range("D" & LR + 1).Value = Target.Value .Range("E" & LR + 1).Value = Environ("username") End With Application.EnableEvents = True Sheet("Log").Unprotect Password:="Willow123" End Sub  

this code... needs to be inside a Sub... (the first line after Option Explicit) Sheet("Log").Protect Password:="Willow123", DrawingObjects:=True, Contents:=True, Scenarios:=True  

Similar threads

  • AT_TreeFortConsulting
  • Feb 8, 2024

PeteWright

  • Jan 9, 2024
  • Greenbehindthecells
  • Nov 9, 2023

melodramatic

  • melodramatic
  • Dec 30, 2023

Forum statistics

Share this page.

excel solver error 1004

We've detected that you are using an adblocker.

Which adblocker are you using.

AdBlock

Disable AdBlock

excel solver error 1004

Disable AdBlock Plus

excel solver error 1004

Disable uBlock Origin

excel solver error 1004

Disable uBlock

excel solver error 1004

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

"Run-time Error 1004" when you make changes to legend entries in a chart in Excel

  • 5 contributors
  • Applies to: Microsoft Excel

When you run a Microsoft Visual Basic for Applications (VBA) macro that uses the LegendEntries method to make changes to legend entries in a Microsoft Excel chart, you may receive the following error message:

Run-time error '1004': Application or object-defined error

This behavior occurs when the Excel chart contains more legend entries than there is space available to display the legend entries on the Excel chart. When this behavior occurs, Microsoft Excel may truncate the legend entries.

Because the LegendEntries method in your VBA macro uses what appears for the legend (in this case, the truncated legend entries), the error message that is mentioned in the "Symptoms" section of this article occurs when there are more entries than there is space available to display the legend entries on the Excel chart.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs.

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

https://support.microsoft.com

To work around this behavior, create a macro that reduces the font size of the Excel chart legend text before your VBA macro makes changes to the chart legend and then restore the font size of the chart legend so that it is similar to the following macro example.

You must have an Excel chart on your worksheet for this macro to run correctly.

Was this page helpful?

Submit and view feedback for

Additional resources

excel solver error 1004

IMAGES

  1. [4 Ways] How to Fix Runtime Error 1004 in Excel

    excel solver error 1004

  2. Fixed--Runtime Error 1004 in Microsoft Excel

    excel solver error 1004

  3. ¿Cómo solucionar el error 1004 en tiempo de ejecución de Excel?

    excel solver error 1004

  4. [4 Ways] How to Fix Runtime Error 1004 in Excel

    excel solver error 1004

  5. How to Fix Excel Run Time Error 1004

    excel solver error 1004

  6. Solutions for Runtime error 1004 Archives

    excel solver error 1004

VIDEO

  1. Solve Sum Error In Excel

  2. 6. Application of Excel Solver to Solve LPP MMPO

  3. How to Solve A error in MS excel

  4. Solve error "E+11" in Excel by Numbers Formatting

  5. Excel VBA

  6. How To Automate Your VLOOKUP In Excel VBA (SAME WORKBOOK)

COMMENTS

  1. [Solved]: How to Fix Excel "Run-Time Error 1004" in Minutes

    There can be several reasons why you get the Runtime Error 1004 in Excel. After researching through different community platforms, we have found the common causes include: 1. Invalid or Corrupted Data: If your spreadsheet contains invalid or corrupted data, it can trigger an error when attempting to perform operations on that data. 2.

  2. Run Time Error 1004: 3 Ways to Fix it

    The Excel runtime error 1004 could show up due to a variety of other underlying issues. The most common error messages include the following: VB: run-time error 1004: Application-defined or object-defined error Excel VBA Runtime error 1004 Select method of Range class failed runtime error 1004 method range of object _global failed visual basic

  3. excel solver runtime error 1004

    asked Jan 27, 2017 at 13:19 user7408924 97 2 10 Your last two constraints (= 0), are you sure, these are correct? - MGP Jan 27, 2017 at 13:23 What I would do is the following: Since you want to minimize your 3 delta_KI values at once. In another column, lets say in E5 you sum the delta_KI values.

  4. Excel VBA Runtime Error 1004

    Table of Contents What is the VBA Runtime Error 1004? Reason #1: VBA Code Refers to Range that Doesn't Exist Reason #2: VBA Code Refers to a Misspelled or Non-existent Named Range Reason #3: VBA Code Attempts to Rename a Worksheet to Name Already Taken Reason #4: VBA Code Attempts to Select Range on a Worksheet that is Not Active

  5. Fix Runtime Error 1004 VBA Excel Macro

    Runtime error 1004 is an error code relating to Microsoft Visual Basic that has been known to disturb Microsoft Excel users. This error is faced by any version of MS Excel, such as...

  6. Excel Run-time Error 1004

    The RTE 1004 means nothing and occurs in different scenarios... more or less "something unspecific gone wrong, don't know why". The basic problem of your code is that you use SELECT and SELECTION. Please never use SELECT, SELECTION, ACTIVECELL, it is slow and error prone.

  7. [4 Ways] How to Fix Runtime Error 1004 in Excel

    Fix 1. Repair Corrupted Excel Files Due to Error 1004 Fix 2. Delete the GWXL97.XLA Files to Fix Runtime Error 1004 in Excel Fix 3. Check the Trust Access to the VBA Project Object Model Fix 4. Create Another Excel Template to Fix Runtime Error 1004 in Excel The Bottom Line Home > File Recovery Updated by Dany on Nov 20, 2023

  8. How to Fix Run-Time Error 1004 in Excel?

    The **Run-time error 1004** in Excel usually occurs when running macros or modifying ranges/cell values. It often occurs when there is an issue with the VBA...

  9. Resolve Excel Run Time Error 1004: Troubleshooting Guide

    Encounter Run Time Error 1004 in Excel? Follow this step-by-step troubleshooting guide to fix the issue and get your spreadsheet back on track.

  10. Run-time error '1004': Activate method of Worksheet class failed

    Quit Excel and start it normally. Select File > Options. Select Add-ins in the navigation pane on the left. Make a note of which add-ins are active. Then use the Go... button near the bottom to disable all active add-ins. The problem should now be gone. Then activate the add-ins one by one, each time checking whether the problem reappears.

  11. i keep getting a runtime error 1004 application defined or object

    Run Excel in Safe-mode, tap and hold "Ctrl" key the open the app, should be appears a pop up window that you try to run Excel in Safe-mode, click on Yes, then check out app behavior. 2. If it's work fine, the issue could be related to an add-in in the app, you should remove the add-ins installed on the app.

  12. How to Fix Excel File Runtime Error 1004[2024]

    Fix 1: Uninstall Microsoft Work Excel runtime error 1004 is the error that occurs when the excel file is corrupted. This can be resolved by Uninstalling Microsoft Work by following the below steps: Before uninstalling Microsoft work, you have to stop all the running programs by pressing "ctrl+alt+delete" and opening "Task Manager".

  13. How to Fix Excel Run Time Error 1004

    Alexis Llontop Updated on September 6th, 2023 Summary: Run-time errors are windows-specific issues that occur while the program is running. This blog will teach you how to fix Excel run-time error 1004. In addition, you'll learn about an Excel repair tool that can help fix the error 1004 if it occurs due to corruption in Excel files.

  14. Receiving Run-time error '1004' when trying to use Solver in Excel

    - Restart the computer. Sometimes VBA gets itself tied up in knots. - If that doesn't work, click "Reset All" in Solver. This will delete everything in the Solver dialog, so you'll need to rebuild the model. If the model is still misbehaving, then upload it somewhere, so we can have a look. rmanwar333 • 3 yr. ago Solution Verified

  15. [Fixed!] Excel VBA Run Time Error 1004

    1. Use Same Name in Naming Sheet One of the most frequent reasons for having the Run Time Error is to try to name the same name in another sheet. If you try to run the VBA after naming the same name of a sheet whose name already exists, a MsgBox will appear with the message That Name is already taken. Try a different One.

  16. Run time error 1004 SOLVER

    23 Run time error 1004 SOLVER Hey, I have a macro in the last of my spreadsheets which just won't work. It's a macro which supposedly should be able to solve the Max DB by changing price (pris).

  17. What is Excel runtime error 1004, and how to fix it?

    Tap on Start and then on Run. Now, type cpl and then press OK. Now, go to option Add or Remove Programs afterward look for MS works. Then right-click on that and uninstall the program successfully. If you are unable to rectify the issue by this fix too, then follow the next method.

  18. "Run-Time error '1004' How to solve this problem

    Thank! Thats a great idea and I will try that. So if I protect the vba project and unprotect the sheet tab (log) this means that users can change the data in the tab (log) and I was hoping that could not be done I need to record every entry that is made to that workbook.

  19. Unable to make changes to legend entries in a chart in Excel

    Sub ResizeLegendEntries () With Worksheets ("Sheet1").ChartObjects (1).Activate ' Store the current font size fntSZ = ActiveChart.Legend.Font.Size 'Temporarily change the font size. ActiveChart.Legend.Font.Size = 2 'Place your LegendEntries macro code here to make 'the changes that you want to the chart legend. ' Restore the font size.

  20. excel

    1 1 1 If you're trying to find the last row, see this question for a better approach. - BigBen Dec 7, 2020 at 13:58 1 you most likely are finding the last row with Range ("B2").End (xlDown) then with .Offset (1, 0) you are trying to select the row below the last row and there is no row to select.

  21. how to solve error 1004 on Mac

    Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.