+ Reply to Thread
Results 1 to 6 of 6

Using variables in a range.select statement

  1. #1
    Forum Contributor
    Join Date
    07-03-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    139

    Using variables in a range.select statement

    I have posted this in a different thread, however I cannot find that thread in a search and the site crashed at the same time I posted, so I am reposting.
    I have the following code which works fine:


    Please Login or Register  to view this content.
    HOWEVER, when I plug variables into this rather than cell addresses, I get method of object _Global failed error, it errors out on the Range("StC:ACol" & LastRow).Selec line of code. Below is the code that fails

    Please Login or Register  to view this content.
    Any Thoughts?
    Last edited by lday75; 07-25-2012 at 12:58 PM. Reason: code tag in wrong place

  2. #2
    Forum Contributor
    Join Date
    07-05-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2016
    Posts
    165

    Re: Using variables in a range.select statement

    Ranges with variables are possible, but VBA is picky about the way it wants it.
    I believe I know what the issue is, but can you provide a sample with some fake data that I could manipulate?
    Click on the * icon if this post has been helpful.

  3. #3
    Forum Contributor
    Join Date
    07-03-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: Using variables in a range.select statement

    Unfortunately no, I can only post even just pieces of code due to the nature of the data, client financial data. Plus this involves a VLOOKUP that pulls from 3 different books, so to have functionality samples it would involve 4 files and replacing a ton of data with pseudo data. My apologies. What is throwing me is that the first Range line also produced the same error and then I removed the " " from around the variable name and it went past that.

    Please Login or Register  to view this content.
    changed from
    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    Last edited by lday75; 07-25-2012 at 01:18 PM. Reason: changed tags

  4. #4
    Forum Contributor
    Join Date
    07-05-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2016
    Posts
    165

    Re: Using variables in a range.select statement

    Is it only the:
    Please Login or Register  to view this content.
    that is giving you the problem or are all three (3) where you use the variable?

    Please Login or Register  to view this content.
    Try

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    07-03-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: Using variables in a range.select statement

    Xer2 - You ROCK. Thank you so much, this did the trick, works perfectly.

  6. #6
    Forum Contributor
    Join Date
    07-05-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2016
    Posts
    165

    Re: Using variables in a range.select statement

    Thank you, and you're welcome. I'm just glad to help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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