+ Reply to Thread
Results 1 to 4 of 4

problem selecting a range using variables

  1. #1
    cass calculator
    Guest

    problem selecting a range using variables

    I'm trying to select a range with the use of variables rather than hard
    inputs. I am getting an error that says "expected list seperator" when
    I type the last line of code. Can you guys tell me why this code
    doesnt work?

    Private Sub stringtest()
    Dim col_1 As Long
    Dim col_2 As Long
    Dim row_1 As String
    Dim row_2 As String

    col_1 = 1
    col_2 = 2
    row_1 = A
    row_2 = B

    Range(col_1&row_1&":"&col_2&row_2&).Select

    End Sub


  2. #2
    Forum Contributor colofnature's Avatar
    Join Date
    05-11-2006
    Location
    -
    MS-Off Ver
    -
    Posts
    301
    You'll need to take out the last & sign to make the line:
    Range(col_1 & row_1 & ":" & col_2 & row_2).Select

    Or replace this lign with:
    Range(Cells(row_1, col_1), Cells(row_2, col_2)).Select

  3. #3
    cass calculator
    Guest

    Re: problem selecting a range using variables

    yeah, sorry that last & was my mistake. when I use the line below, it
    selects the entire row A and B. I just want to select A1:B2 though.

    Range(Cells(row_1, col_1), Cells(row_2, col_2)).Select

    Any help on just selecting a given range and not the entire row?

    Thanks,

    Joshua


  4. #4
    Michael
    Guest

    Re: problem selecting a range using variables

    This will select A1:B2

    Sub One()
    row1 = 1
    row2 = 2
    col1 = 1
    col2 = 2


    Range(Cells(row1, col1), Cells(row2, col2)).Select



    End Sub


    "cass calculator" wrote:

    > yeah, sorry that last & was my mistake. when I use the line below, it
    > selects the entire row A and B. I just want to select A1:B2 though.
    >
    > Range(Cells(row_1, col_1), Cells(row_2, col_2)).Select
    >
    > Any help on just selecting a given range and not the entire row?
    >
    > Thanks,
    >
    > Joshua
    >
    >


+ 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