+ Reply to Thread
Results 1 to 6 of 6

Using variable in Range in Sub

  1. #1
    Registered User
    Join Date
    03-03-2011
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    53

    Using variable in Range in Sub

    Hi

    I seem to be confusing the use of variables in ranges somehow so would appreciate help. The code below is intended to highlight one row as defined by the variable r which is a for next counter, but instead it highlights the whole sheet.

    Please Login or Register  to view this content.
    The routines below to clear certain columns and remove all formatting before running work fine but these variables are not part of a loop counter.
    Please Login or Register  to view this content.
    Some insight from the more experienced as to what I am doing wrong would be greatly appreciated.
    Last edited by Orada; 03-03-2011 at 12:48 PM.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Using variable in Range in Sub

    Instead of
    Please Login or Register  to view this content.
    Try:
    Please Login or Register  to view this content.
    Instead of
    Please Login or Register  to view this content.
    Try:
    Please Login or Register  to view this content.

  3. #3
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Using variable in Range in Sub

    Your first bit of code should select A1:S1 (or whatever r equals) - are you saying it doesn't? Apart from unnecessary use of Select your use of variables looks fine to me.

  4. #4
    Registered User
    Join Date
    03-03-2011
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Using variable in Range in Sub

    Quote Originally Posted by stnkynts View Post
    Try:
    Please Login or Register  to view this content.
    Try:
    Please Login or Register  to view this content.
    Thanks but got runtime error - Method chance of object global failed.

  5. #5
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Using variable in Range in Sub

    Could you submit your whole code or a copy of the workbook for review?

  6. #6
    Registered User
    Join Date
    03-03-2011
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Using variable in Range in Sub

    Quote Originally Posted by StephenR View Post
    Your first bit of code should select A1:S1 (or whatever r equals) - are you saying it doesn't? Apart from unnecessary use of Select your use of variables looks fine to me.
    OK, I'm losing the variable, when r is null then the complete worksheet gets selected for format.

    I'll get it sorted now, thanks, I had been calling the routine from a workbook

+ 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