+ Reply to Thread
Results 1 to 7 of 7

Adding wider range to VBA code gives error 1004

  1. #1
    Registered User
    Join Date
    09-29-2021
    Location
    Lund, Sweden
    MS-Off Ver
    Microsoft 365 Apps for enterprise
    Posts
    15

    Adding wider range to VBA code gives error 1004

    Hey all!

    Having trouble with my VBA code which is used to clear the contents of a specific range of cells. It works well up to a specific range, but when I add another one it gives me "Runt-time error '1004': Method 'Range' of object '_Global' failed".

    This is my code when it is working:
    Please Login or Register  to view this content.
    As soon as I add the range E175:W178 it gives me the error

  2. #2
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: Adding wider range to VBA code gives error 1004

    Hi
    Try some thing like this
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    293

    Re: Adding wider range to VBA code gives error 1004

    I'm not entirely sure why that happens, I tried myself and found the same issue.

    However, this code should do the same trick;

    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: Adding wider range to VBA code gives error 1004

    Ok
    BUT what about speed?

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,996

    Re: Adding wider range to VBA code gives error 1004

    Quote Originally Posted by PrizeGotti View Post
    I'm not entirely sure why that happens
    The range property is limited to an argument of 255 characters at most. In the working code, it's at 253, so adding the additional range takes it over that limit.
    Everyone who confuses correlation and causation ends up dead.

  6. #6
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    293

    Re: Adding wider range to VBA code gives error 1004

    Quote Originally Posted by mohadin View Post
    Ok
    BUT what about speed?
    Not entirely sure what you mean? Either way completes in well under a second.

  7. #7
    Registered User
    Join Date
    09-29-2021
    Location
    Lund, Sweden
    MS-Off Ver
    Microsoft 365 Apps for enterprise
    Posts
    15

    Re: Adding wider range to VBA code gives error 1004

    Quote Originally Posted by PrizeGotti View Post
    I'm not entirely sure why that happens, I tried myself and found the same issue.

    However, this code should do the same trick;

    Please Login or Register  to view this content.
    Thanks alot that worked well!
    Last edited by Christianekstrom; 12-02-2021 at 03:35 AM.

+ 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. [SOLVED] Run-time Error 1004, delete method of range class failed? (Code included)
    By LIL2606 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-05-2019, 02:11 PM
  2. Replies: 9
    Last Post: 11-15-2018, 06:46 AM
  3. [SOLVED] Runtime error 1004 range of object with VBA code for copying all worksheets to word
    By vtcin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-24-2014, 07:15 AM
  4. Replies: 4
    Last Post: 11-15-2013, 05:03 PM
  5. VBA Code...error = run time error 1004 autofilter method of range class failed
    By Dariusd7 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-15-2013, 04:49 PM
  6. [SOLVED] Range error in code, runs alone but not inside my full program, giving runtime error 1004
    By charizzardd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-23-2012, 03:34 PM
  7. Adding library references with code -> error 1004
    By cyc1120 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-12-2008, 12:29 PM

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