+ Reply to Thread
Results 1 to 3 of 3

VBA - how to select a big range with a variable?

  1. #1
    Registered User
    Join Date
    05-19-2010
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    5

    VBA - how to select a big range with a variable?

    Greetings,

    I need to select a range on excel based on an i variable in a "for" loop. But can't figure out how.

    Example:

    For i = 3 To 99999
    Range("A" & i).Select
    Next

    But i want to do that in a Range(A1:J1) style.

    I tried Range("A"&i&:&"J"&i) and a lot of combinations, but no one worked.

    Thanks for any help

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA - how to select a big range with a variable?

    Hi,

    I'm guessing you want:

    Please Login or Register  to view this content.
    However consider whether you really need to use the .Select instruction. Selects and Activates are rarely needed and since there is a time overhead involved with these since VBA has to jump back to the Excel application, in a large loop like yours this will slow things down considerably.

    For instance if you're copying the range just refer to the Range object directly and use the .Copy instead of .Select.

    HTH
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

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

    Re: VBA - how to select a big range with a variable?

    Please Login or Register  to view this content.
    a real big range would be

    Please Login or Register  to view this content.

+ 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