Consulting

Results 1 to 3 of 3

Thread: Solved: Help with resize

  1. #1
    VBAX Expert
    Joined
    Dec 2007
    Posts
    522
    Location

    Solved: Help with resize

    Hi All,

    I am doing the following:
    [vba]
    Option Explicit

    Sub test()

    ThisWorkbook.Worksheets("Expected").Range("T1").Resize(1, -16).calculate

    End Sub[/vba]
    That is, select the relevant region with respect to T1 and calculate it.

    However, I will be requiring to calculate this many times in a loop and wanted to SET this calculation range in the macro as follows:

    [vba]Option Explicit

    Sub test()

    Dim rng As Range

    Set rng = ThisWorkbook.Worksheets("Expected").Range("T1").Resize(1, -16)

    ' Then do more steps here and then recalculate range

    rng.Calculate

    End Sub[/vba]
    The red throws an '1004' error Application defined or object defined error.

    Ani ideas on how to correct for this as optimally as possible (i.e. without selecting the rng)?

    Any help appreciated.
    Last edited by xluser2007; 12-02-2008 at 07:12 PM.

  2. #2
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    You have to resize from the other direction (right/down), so just Offset it to the left, then resize to the right...

    [vba]Option Explicit

    Sub test()

    Dim rng As Range

    Set rng = ThisWorkbook.Worksheets("Expected").Range("T1").Offset(0, -15).Resize(1, 16)

    ' Then do more steps here and then recalculate range

    rng.Calculate

    End Sub[/vba]

    HTH

  3. #3
    VBAX Expert
    Joined
    Dec 2007
    Posts
    522
    Location
    Quote Originally Posted by Zack Barresse
    You have to resize from the other direction (right/down), so just Offset it to the left, then resize to the right...

    [vba]Option Explicit

    Sub test()

    Dim rng As Range

    Set rng = ThisWorkbook.Worksheets("Expected").Range("T1").Offset(0, -15).Resize(1, 16)

    ' Then do more steps here and then recalculate range

    rng.Calculate

    End Sub[/vba]
    HTH
    Works a treat Zack, appreciate your help !

Posting Permissions

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