+ Reply to Thread
Results 1 to 3 of 3

Describing a Range with Variables

  1. #1
    mazo
    Guest

    Describing a Range with Variables

    Hi

    I have the following problem:
    I want to select a certain Range depending on the value of a variable

    e.g.
    I habe a variable called nr (current value = 1)
    I want to replace:

    Range("O1:O200").Select

    with:

    " Range [ Cells(1,(14+nr)) to Cells(200,(14+nr)) ]"

    How can you wright that in VBA?

    Mazo


  2. #2
    Norman Jones
    Guest

    Re: Describing a Range with Variables

    Hi Mazo,

    You are almost there! Try:

    Dim rng As Range

    Set rng = Range(Cells(1, 14 + i), Cells(200, 14 + i))


    ---
    Regards,
    Norman



    "mazo" <[email protected]> wrote in message
    news:[email protected]...
    > Hi
    >
    > I have the following problem:
    > I want to select a certain Range depending on the value of a variable
    >
    > e.g.
    > I habe a variable called nr (current value = 1)
    > I want to replace:
    >
    > Range("O1:O200").Select
    >
    > with:
    >
    > " Range [ Cells(1,(14+nr)) to Cells(200,(14+nr)) ]"
    >
    > How can you wright that in VBA?
    >
    > Mazo
    >




  3. #3
    Dave Peterson
    Guest

    Re: Describing a Range with Variables

    Another way:

    Dim myRng as range
    dim nr as long
    nr = 1 'or something

    set myrng = activesheet.cells(1,14+nr).resize(1,200)

    ..resize(1,200) means to take the original range (cells(1,14+nr) and resize it to
    1 row by 200 columns.





    mazo wrote:
    >
    > Hi
    >
    > I have the following problem:
    > I want to select a certain Range depending on the value of a variable
    >
    > e.g.
    > I habe a variable called nr (current value = 1)
    > I want to replace:
    >
    > Range("O1:O200").Select
    >
    > with:
    >
    > " Range [ Cells(1,(14+nr)) to Cells(200,(14+nr)) ]"
    >
    > How can you wright that in VBA?
    >
    > Mazo


    --

    Dave Peterson

+ 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