+ Reply to Thread
Results 1 to 4 of 4

Run-time error 1004 Application=defined or object-defined error

  1. #1
    Forum Contributor
    Join Date
    01-08-2017
    Location
    Salt Lake City, Ut.
    MS-Off Ver
    2019 and 365
    Posts
    135

    Question Run-time error 1004 Application=defined or object-defined error

    I used the following code to change the font colors from red to green or vice versa. It works most of the time, but then I will get the Run-time error 1004 Application=defined or object-defined error. When that happens it pretty much locks up. I can reset the code, but it will just occur again. I have searched high and low for a solution but have been unable to find one.



    Please Login or Register  to view this content.
    Any ideas or solutions would be appreciated
    Last edited by dentler; 06-20-2020 at 01:11 PM.

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Run-time error 1004 Application=defined or object-defined error

    Try this:

    Please Login or Register  to view this content.
    Tested it here and no error
    Last edited by Keebellah; 06-12-2020 at 06:03 PM.
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Forum Contributor
    Join Date
    01-08-2017
    Location
    Salt Lake City, Ut.
    MS-Off Ver
    2019 and 365
    Posts
    135

    Re: Run-time error 1004 Application=defined or object-defined error

    I apologize for not getting back to this quickly, but I have been busy coding. Keebellah, although your recommended solution did not resolve my problem, it did help point me in the right direction. I found changing the colors to vbRed or vbGreen did not resolve my problems and the green was to light to read in my spreadsheet, so I went to RGB color sets instead, which allowed me to select the color of Green that was more easily readable. That also did not resolve my problem, and as usual when changing code in one area, sometimes it introduces problems with code in other areas. So I had to rewrite several areas in my code that used these color codes. One again, that alone did not resolve my problem, but in the process I began to realize what was happening. The problem occurred more frequently when I closed my workbook and then reopened it. Double clicks on selected cells with Red or Green would cause the Run-time error 1004. This would also occur more infrequently when double clicking on targets in other worksheets.

    What I did not explain earlier, if you look at my original code, is that in columns P and Q, I would store values 1 or 2 depending on the colors. The value one would represent the color change to green, while the value 2 would represent the color Red. Why did I do this? Well, initially it was so that if I exported the worksheet, I would have those values in my export, and then if I chose to import them back into my workbook, I could reference those two columns and run code to return the targeted values back to their original colors prior to the export.

    After making the changes to the RGB color sets, then I sought to resolve the Run-time error 1004. I then created the following code to Reset the Font colors:

    Please Login or Register  to view this content.
    I then implemented this code to run in primarily two areas, one anytime there was a switch to another worksheet with color codes, this code would run when the sheet was activated to reset those colors and it would resolve the occasional Run-time error 1004 that I would sometimes get when switching between sheets. Still the problem occurred when I would close and reopen my workbook and then try to double click on a target to change colors. The solution here was to enter code into the Workbook_Activate routine, to identify when certain ledgers were selected and run the ResetFonts routine once the worksheets was selected, thus resolving the primary issue that would give me the Run-time error 1004.

    So my problem is resolved, one that I spent many hours on both trying to initially find a solution, and then more hours creating and editing my solution above into my code.

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Run-time error 1004 Application=defined or object-defined error

    Good to hear. Your efforts represent everything VBA is, patience, time and perseverance.
    Happy coding

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 10-22-2015, 05:50 AM
  2. VBA ERROR: run time error 1004: Application-defined or Object-defined error in excel 2013
    By AnanthKrishna in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-13-2015, 06:16 AM
  3. excel macro run time error '1004'- Application defined or object defined error
    By kmadan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-16-2014, 09:51 AM
  4. Replies: 1
    Last Post: 03-12-2014, 12:42 PM
  5. [SOLVED] Run time error 1004 Application-Defined or Object-Defined Error - Placing data into next e
    By michelle 1 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-27-2014, 12:57 PM
  6. [SOLVED] Error " Run-time error '1004': application defined or object defined error
    By lengwer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-11-2013, 07:26 AM
  7. [SOLVED] run-time error '1004' application-defined or object-defined error - Excel 2007
    By kaurka in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2012, 02:46 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1