+ Reply to Thread
Results 1 to 4 of 4

Using Select with Range.Cells property

  1. #1
    Ralph Heidecke
    Guest

    Using Select with Range.Cells property

    Can anyone tell me why:

    Range(Cells(iNameR, iNameC + 3), Cells(iNameR, iNameC + iCount + 2)).Select

    works while:

    Range(Cells(iTargetR, iTarDateC)).Select

    returns the runtime error '1004' method 'Range' of object '_Global'

    TIA


    --
    remove 901 from reply email for valid address.

    [email protected]
    -----
    remove



  2. #2
    Rob van Gelder
    Guest

    Re: Using Select with Range.Cells property

    Assuming here that iTargetR is an integer between 1 and 65536 and iTarDateC
    is an integer between 1 and 256

    Try just Cells(iTargetR, iTarDateC).Select


    --
    Rob van Gelder - http://www.vangelder.co.nz/excel


    " Ralph Heidecke" <[email protected]> wrote in message
    news:%S0Gd.81947$8l.66029@pd7tw1no...
    > Can anyone tell me why:
    >
    > Range(Cells(iNameR, iNameC + 3), Cells(iNameR, iNameC + iCount +
    > 2)).Select
    >
    > works while:
    >
    > Range(Cells(iTargetR, iTarDateC)).Select
    >
    > returns the runtime error '1004' method 'Range' of object '_Global'
    >
    > TIA
    >
    >
    > --
    > remove 901 from reply email for valid address.
    >
    > [email protected]
    > -----
    > remove
    >
    >




  3. #3
    Tom Ogilvy
    Guest

    Re: Using Select with Range.Cells property

    Range can not take a single range object as an argument. Range(Range1) is
    not legal syntax. Range(Range1,Range2) is. (Rangex represents a range
    object).

    --
    Regards,
    Tom Ogilvy
    " Ralph Heidecke" <[email protected]> wrote in message
    news:%S0Gd.81947$8l.66029@pd7tw1no...
    > Can anyone tell me why:
    >
    > Range(Cells(iNameR, iNameC + 3), Cells(iNameR, iNameC + iCount +

    2)).Select
    >
    > works while:
    >
    > Range(Cells(iTargetR, iTarDateC)).Select
    >
    > returns the runtime error '1004' method 'Range' of object '_Global'
    >
    > TIA
    >
    >
    > --
    > remove 901 from reply email for valid address.
    >
    > [email protected]
    > -----
    > remove
    >
    >




  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Quote Originally Posted by Ralph Heidecke
    Can anyone tell me why:

    Range(Cells(iNameR, iNameC + 3), Cells(iNameR, iNameC + iCount + 2)).Select

    works while:

    Range(Cells(iTargetR, iTarDateC)).Select

    returns the runtime error '1004' method 'Range' of object '_Global'

    TIA


    --
    remove 901 from reply email for valid address.

    [email protected]
    -----
    remove

    Hi Ralph,

    Here is an excerpt from Microsoft's Online VBA Help File....
    ________________________________________________________________

    Cells Property

    Use Cells(row, column) where row is the row index and column is the column index, to return a single cell. The following example sets the value of cell A1 to 24.

    Worksheets(1).Cells(1, 1).Value = 24

    The following example sets the formula for cell A2.

    ActiveSheet.Cells(2, 1).Formula = "=sum(b1:b5)"

    Although you can also use Range("A1") to return cell A1, there may be times when the Cells property is more convenient because you can use a variable for the row or column. The following example creates column and row headings on Sheet1. Notice that after the worksheet has been activated, the Cells property can be used without an explicit sheet declaration (it returns a cell on the active sheet).

    Sub SetUpTable()
    Worksheets("sheet1").Activate
    For theYear = 1 To 5
    Cells(1, theYear + 1).Value = 1990 + theYear
    Next theYear
    '
    For theQuarter = 1 To 4
    Cells(theQuarter + 1, 1).Value = "Q" & theQuarter
    Next theQuarter
    End Sub

    Although you could use Visual Basic string functions to alter A1-style references, it's much easier (and much better programming practice) to use the Cells(1, 1) notation.

    Use expression.Cells(row, column) , where expression is an expression that returns a Range object, and row and column are relative to the upper-left corner of the range, to return part of a range. The following example sets the formula for cell C5.

    Worksheets(1).Range("c5:c10").Cells(1, 1).Formula = "=rand()"

    ________________________________________________________________

    HTH
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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