Results 1 to 10 of 11

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    Hello barbosajulio77
    Welcome to ExcelFox, the thinking man’s excel forum…


    I am not 100% sure what your problem is, but possibly the Resize function does not work on a multi area range object. ( I don't know this for sure ** )

    Let me explain:

    This is your rngDst, A17:C17, E17

    Row\Col
    A
    B
    C
    D
    E
    F
    16
    17
    Cell in Area 1 Cell in Area 1 Cell in Area 1 Cell in Area 2
    18
    Worksheet: STATEMENT

    Your range, rngDst , shown above has two areas, as I have shown, A17:C17 is Area item 1 and E17 is Area item 2

    I did some experimenting, like in the macros below, and you can see that the first macro, ( which does something similar to your macro at your problem code line), does not work. It gives the same error as you are seeing.
    The other 3 macros do work.

    The first macro, which errors, is trying to resize a multi area range. The other macros, which do work, are applying the resize function to a single area range object

    This first macro will error
    Code:
    Sub DoesNotWork() ' This will error -  run-time error 1004 application-defined or object-defined error
    Dim rngDst As Range
     Set rngDst = ActiveSheet.Range("A17:C17, E17")
     Let rngDst.Resize(2, 1).Value = "You will never see this" ' ' This code line will error -  run-time error 1004 application-defined or object-defined error
    End Sub


    The following 3 macros all work and give the results shown
    Code:
    Sub DoesWork_1()
    Dim rngDst As Range
     Set rngDst = ActiveSheet.Range("A17:C17")
     Let rngDst.Resize(2, 1).Value = "Resized Cells of Single Area Range"
    End Sub
    Row\Col A B C D
    16
    17 Resized Cells of Single Area Range
    18 Resized Cells of Single Area Range
    19
    Worksheet: STATEMENT

    Code:
    Sub DoesWork_2()
    Dim rngDst As Range
     Set rngDst = ActiveSheet.Range("A17:C17, E17")
     Let rngDst.Areas.Item(1).Resize(2, 1).Value = "Resized Cells of Area 1 of multi area Range"
    End Sub
    
    Row\Col A B C D
    16
    17 Resized Cells of Area 1 of multi area Range
    18 Resized Cells of Area 1 of multi area Range
    19
    Worksheet: STATEMENT


    Code:
    Sub DoesWork_3()
    Dim rngDst As Range
     Set rngDst = ActiveSheet.Range("A17:C17, E17")
     Let rngDst.Areas.Item(2).Resize(2, 1).Value = "Resized Cells of Area 2 of multi area Range"
    End Sub
    
    Row\Col A B C D E
    16
    17 Resized Cells of Area 2 of multi area Range
    18 Resized Cells of Area 2 of multi area Range
    19
    20
    Worksheet: STATEMENT



    ** I was not aware that the resize function errors if applied to a multi area range object, so maybe I have learnt something as well from this Thread…
    ( Note , that as is usual and as is known to me, the resize function works on the top left of the supplied range. So for the first 2 working macros it is resizing cell A17. For the last macro it is resizing cell E17 )


    Hope that is some help to you
    Alan
    Last edited by DocAElstein; 08-14-2021 at 03:44 PM.

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
  •