+ Reply to Thread
Results 1 to 3 of 3

Can't assign range variable inside For loop

  1. #1
    Forum Contributor
    Join Date
    07-08-2008
    Location
    New York City
    MS-Off Ver
    2013-2016
    Posts
    157

    Can't assign range variable inside For loop

    Hi, I was wondering if someone could help me with this.
    I'm looking for a cell with a specific background color. I need to put the range of the found cell into a variable so i can refer to it later, but i can't.
    I tried different things but the closest I get is a Type Mismatch error and don't understand why. I declared the variable as Range and I'm setting it to an Address. In my mind it should work, but it doesn't.
    Check the part of the code where [MsgBox var.Address] is. The box shows a range (like $E$4), but when i replace the MsgBox line with: [Set var = var.address] then i get the error. What am i doing wrong?

    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Can't assign range variable inside For loop

    Something like this.
    Do not recommend to use vb reserved word like "val" as a variable name.
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    07-08-2008
    Location
    New York City
    MS-Off Ver
    2013-2016
    Posts
    157

    Re: Can't assign range variable inside For loop

    Jindon, it works perfectly! Also followed your recommendation and changed the name of the variable.
    Thank you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Assign range to a class variable array
    By Lithium in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-07-2015, 11:45 AM
  2. Why did an inner loop variable start overwriting the outer loop range suddenly?
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-16-2012, 03:24 PM
  3. How to use variable inside Range?
    By amithreat in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-26-2010, 08:22 PM
  4. Assign and found range to a variable
    By duckboy1981 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-26-2009, 10:55 AM
  5. How to assign an imported XML worksheet range to a VBA variable?
    By tonybreyal in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-11-2009, 02:34 PM
  6. Using a range variable inside a excel function
    By Michael in forum Excel General
    Replies: 2
    Last Post: 11-14-2005, 10:55 AM
  7. [SOLVED] How to assign a variable in a range select
    By Paul in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-03-2005, 07:05 PM

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