+ Reply to Thread
Results 1 to 7 of 7

Select Range using variables

  1. #1
    Registered User
    Join Date
    11-29-2009
    Location
    dubai
    MS-Off Ver
    Excel 2003
    Posts
    56

    Select Range using variables

    Hi,

    I have set variables to identify the first row, last row, and last column. when I try to select the range it gives me an error.


    Please Login or Register  to view this content.
    Thanks
    R
    Last edited by rvc81; 12-08-2010 at 08:05 AM.

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Select Range using variables

    No need for variables:
    Please Login or Register  to view this content.
    maybe this will give the same result
    Please Login or Register  to view this content.
    or even
    Please Login or Register  to view this content.
    But in general you should avoid 'activate' and 'select' in VBA.
    Last edited by snb; 12-08-2010 at 07:01 AM.



  3. #3
    Registered User
    Join Date
    11-29-2009
    Location
    dubai
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: Select Range using variables

    thank you so much for the code.

    I have used the the first code, it selects the range but selects 1 extra column and 5 extra rows.

    R

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Select Range using variables

    This will select 1 column and 1 row less:
    Please Login or Register  to view this content.
    Last edited by snb; 12-08-2010 at 07:56 AM.

  5. #5
    Registered User
    Join Date
    11-29-2009
    Location
    dubai
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: Select Range using variables

    with the above code the column selection is ok but it selects 5 extra rows

    Thanks
    R

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Select Range using variables

    Can't tell without seeing your worksheet.
    But most likely the last 5 cells in column A are not empty (although they give that impression). Delete those last 5 rows and try again.

  7. #7
    Registered User
    Join Date
    11-29-2009
    Location
    dubai
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: Select Range using variables

    I think you are right, I tried the code in a new sheet and it works perfectly fine.

    Thanks again.

    R

+ 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