Results 1 to 10 of 11

Thread: Run-time error 1004 when trying to resize a multi area range object

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    Hi
    Quote Originally Posted by barbosajulio77 View Post
    ...how to add your working suggestions to my code that the range ("A17:C17, E17") works?..
    I am not sure exactly what it is you are trying to do, so I am not sure what exactly you mean by “works
    I can’t be sure what your problem is without knowing exactly what you are trying to do. I might also need to see all your files and data, along with a full description of what you are trying to do.


    My initial investigation and experimenting for you suggested that the resize function errors if applied to a multi area range object.
    "A17:C17, E17" is a multi area range object.
    ( Area item 1 is cells A17:C17 __ Area item 2 is the cell E17 )

    As I showed it has two areas. Your code line that errors tries to apply the resize function to that multi area range object, so it errors.

    So we may have found out what is causing the error.




    As I also mentioned at the end of my first post, the resize function actually works on the top left cell of the range you give it.

    So lets look again in detail at the erroring code bit

    rngDst.Offset(0, 4).Resize(rowsize + 1, 1).Value

    That is the same as
    wkbDst.Worksheets("STATEMENT").Range("A17:C17, E17").Offset(0, 4).Resize(rowsize + 1, 1).Value
    So you can see the problem again. You are trying to resize the multi area range object, "A17:C17, E17"
    We have found that this will error

    I don’t know what you want to do. I do not know what you mean by “works
    But let me take a guess that you want to resize the cell A17, since that is the top left cell of your total range. Remember: The resize function resizes based on the top left cell of the range that you give it
    If you want to resize based on the top left of your range, then a modification to the problem code line would be to do this:
    rngDst.Areas.Item(1).Offset(0, 4).Resize(rowsize + 1, 1).Value
    That is the same as
    wkbDst.Worksheets("STATEMENT").Range("A17:C17, E17").Areas.Item(1).Offset(0, 4).Resize(rowsize + 1, 1).Value
    It is also the same as this
    wkbDst.Worksheets("STATEMENT").Range("A17:C17").Offset(0, 4).Resize(rowsize + 1, 1).Value

    Do you see the difference? - The modified code line is now applying the resize function to a single area range object, "A17:C17".
    ( Range("A17:C17, E17").Areas.Item(1) = Range("A17:C17") )
    So it probably will not now error.



    The short answer

    Change this
    Code:
                        rngDst.Offset(0, 4).Resize(rowsize + 1, 1).Value = rngSrc.Value '
    to this
    Code:
                        rngDst.Areas.Item(1).Offset(0, 4).Resize(rowsize + 1, 1).Value = rngSrc.Value
    If that is no good for you, then I can’t help more unless you supply me some data and files and explain fully what it is that you are trying to do.


    Alan
    Last edited by DocAElstein; 08-16-2021 at 02:44 AM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    KILL A MODERATOR!!

Similar Threads

  1. Excel VBA Run-time error '13' Type mismatch
    By mackypogi in forum Excel Help
    Replies: 5
    Last Post: 09-17-2013, 11:16 AM
  2. Replies: 1
    Last Post: 06-18-2013, 07:46 AM
  3. Run Time error '9': Subscript out of range
    By antonio in forum Excel Help
    Replies: 4
    Last Post: 03-26-2013, 01:53 AM
  4. Replies: 4
    Last Post: 05-03-2012, 10:28 AM
  5. Spreading a time range (shift time, etc) in columns.
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 1
    Last Post: 08-23-2011, 11:45 AM

Posting Permissions

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