Closed Thread
Results 1 to 5 of 5

Using R1C1 in VB to select a range

  1. #1
    Robert_L_Ross
    Guest

    Using R1C1 in VB to select a range

    I've seen a lot of posting about using the R1C1 format to select cells when
    using VB to program a function into a cell, but not a lot about how to use
    the R1C1 format to select a range for use in a VB Macro.

    If I am in cell CA91 and I want to select the range starting at CA92 through
    CE176, how to I program that into VB? I tried "range(rc1:r4c84).select" and
    it doesn't like the colon. I then tried "range(rc[1]:r[4]c[84]).select" and
    it bombed on the first open bracket ([).

    Any ideas? I can't use the direct addresses since I won't always know where
    I'm going to start this macro from.

  2. #2
    john
    Guest

    Re: Using R1C1 in VB to select a range

    if you want Range("R1C1:R4C84") to be selected, you can use the following
    code:
    1. Range("A1:CE4").select
    or
    2. Range(Cells(1, 1), Cells(4, 84)).select

    Best Regards
    John Black

    "Robert_L_Ross" <[email protected]> wrote in message
    news:[email protected]...
    > I've seen a lot of posting about using the R1C1 format to select cells

    when
    > using VB to program a function into a cell, but not a lot about how to use
    > the R1C1 format to select a range for use in a VB Macro.
    >
    > If I am in cell CA91 and I want to select the range starting at CA92

    through
    > CE176, how to I program that into VB? I tried "range(rc1:r4c84).select"

    and
    > it doesn't like the colon. I then tried "range(rc[1]:r[4]c[84]).select"

    and
    > it bombed on the first open bracket ([).
    >
    > Any ideas? I can't use the direct addresses since I won't always know

    where
    > I'm going to start this macro from.




  3. #3
    Toppers
    Guest

    RE: Using R1C1 in VB to select a range

    Robert,
    You might find this easier:

    Sub GetRange()
    Dim rng As Range
    Set rng = Range("CA92").Resize(85, 5)
    rng.Select
    End Sub

    Or .... where Activecell=CA91 to use your example

    Sub GetRange()
    Dim rng As Range
    Set rng = ActiveCell.Offset(1, 0).Resize(85, 5)
    rng.Select
    End Sub

    Avoid using select as much as possible as it slows performance. I used it to
    illustrate that the range was correct.

    HTH

    "Robert_L_Ross" wrote:

    > I've seen a lot of posting about using the R1C1 format to select cells when
    > using VB to program a function into a cell, but not a lot about how to use
    > the R1C1 format to select a range for use in a VB Macro.
    >
    > If I am in cell CA91 and I want to select the range starting at CA92 through
    > CE176, how to I program that into VB? I tried "range(rc1:r4c84).select" and
    > it doesn't like the colon. I then tried "range(rc[1]:r[4]c[84]).select" and
    > it bombed on the first open bracket ([).
    >
    > Any ideas? I can't use the direct addresses since I won't always know where
    > I'm going to start this macro from.


  4. #4
    Registered User
    Join Date
    02-21-2013
    Location
    INDIA
    MS-Off Ver
    Excel 2013
    Posts
    2

    Re: Using R1C1 in VB to select a range

    hi

    I want to change the below code into cell ranges instead of r1c1. Also i want this formula for multiple cells

    Sub Item()
    '
    ' Item Macro
    '
    ' Keyboard Shortcut: Ctrl+Shift+I
    '
    With Selection.Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:="=Sheet5!$A$8:$A$156"
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
    End With
    Range("D2:O2").Select
    ActiveCell.FormulaR1C1 = _
    "=VLOOKUP(R2C16,Sheet5!R[6]C[-3]:R[150]C[15],Sheet5!R[4]C[-1],0)"
    Range("D3:O3").Select
    ActiveCell.FormulaR1C1 = _
    "=VLOOKUP(R2C16,Sheet5!R[5]C[-3]:R[147]C[15],Sheet5!R[3]C,0)"
    Range("D4:O4").Select
    ActiveCell.FormulaR1C1 = _
    "=VLOOKUP(R2C16,Sheet5!R[4]C[-3]:R[146]C[15],Sheet5!R[2]C[1],0)"
    Range("D5:O5").Select
    ActiveCell.FormulaR1C1 = _
    "=VLOOKUP(R2C16,Sheet5!R[3]C[-3]:R[145]C[15],Sheet5!R[1]C[2],0)"
    Range("D6:F6").Select


    End Sub


    Pls. kindly help on this

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,460

    Re: Using R1C1 in VB to select a range

    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

Closed 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