+ Reply to Thread
Results 1 to 3 of 3

Changing range selected with variable

  1. #1
    Registered User
    Join Date
    01-17-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    2

    Changing range selected with variable

    I have some code that uses offset to select a column of numbers

    Please Login or Register  to view this content.
    However, I want to vary the range depending on a parameter passed to the routine.
    i.e. Range("A1:A15") can vary - it may not always be A15.

    Initially I naively tried

    Please Login or Register  to view this content.
    but of course that didn't work.
    I tried various attempts at using Cells method, and R1C1 notation but no luck

    The Cells method selects but it is always in reference to the start of the spreadsheet not the active cell.

    Any suggestions?

    Thanks
    Last edited by perlgerl; 01-17-2009 at 01:44 AM.

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    You included Roze-6 inside the " marks which meant Excel treadted it as a text string not a variable & you did not use anthing to join you commands
    To join you need to use & or +
    Personally I prefer to use & leaving the + for formulas

    Please Login or Register  to view this content.
    Another way of doing it is

    Please Login or Register  to view this content.
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  3. #3
    Registered User
    Join Date
    01-17-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    2
    Problem solved!
    Thanks Mudraker

    I tried the
    Range("A1:A" & Roze-6)
    suggestion and it worked fine. I guess I never thought of "A1:A15" as a string. Usually I use the cells method when entering variables into cell positions and always considered the A1 notation as sort of a constant.

    Thanks again

+ 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