+ Reply to Thread
Results 1 to 8 of 8

Select a range based on number next to range

  1. #1
    Registered User
    Join Date
    01-06-2016
    Location
    Baltimore, MD
    MS-Off Ver
    Standard 2010
    Posts
    21

    Select a range based on number next to range

    Hello, I'm a novice VBA user, and have a macro that I want to tweak, because there's an operation within the macro that can take a ton of time with large files. I'm trying to copy and paste a range of cells, and I'm using a Do Until ... Loop right now.

    At this point in the macro, I have a list of SSN's in column H, starting with cell H7, and next to each one, in column I, there is a number indicating how many funds each SSN holds in their portfolio. The list has been sorted by #funds, so all the "1" fund SSN's are at the top. These are the SSN's I want to copy and paste in Column N.

    So, to recap: the list of SSN's starts in cell H7, and the list of #funds starts in cell I7. This is what I wrote:

    Please Login or Register  to view this content.
    So it's looking at the cell in column I, and if it's a "1", it copies the SSN next to it in column H, and pastes it into column N. Then it goes to the next cell in column I, etc. I'm copying and pasting each SSN one at a time.

    Can anyone suggest a way for the macro to select all the SSN's with a "1" next to them, and copy/paste in one grand maneuver?

    Thank you so much!!!! Jake
    Last edited by jakevogel; 07-31-2017 at 01:23 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    07-10-2017
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2013
    Posts
    430

    Re: Select a range based on number next to range

    Is it reasonable to assume that the cell after the desired range will contain "2" since it is sorted?

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Select a range based on number next to range

    Maybe:

    Please Login or Register  to view this content.
    BTW - Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    Last edited by xladept; 07-31-2017 at 01:21 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Registered User
    Join Date
    01-06-2016
    Location
    Baltimore, MD
    MS-Off Ver
    Standard 2010
    Posts
    21

    Re: Select a range based on number next to range

    Yes, the cell after the desired range is "2". Thank you!

  5. #5
    Registered User
    Join Date
    01-06-2016
    Location
    Baltimore, MD
    MS-Off Ver
    Standard 2010
    Posts
    21

    Re: Select a range based on number next to range

    Thank you for letting me know about code tags. I edited my original post.

    I will try your code - thanks so much! Jake

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Select a range based on number next to range

    Hey Jake,

    I wrote that thing in word - here's a working version-sorry

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-06-2016
    Location
    Baltimore, MD
    MS-Off Ver
    Standard 2010
    Posts
    21

    Re: Select a range based on number next to range

    That worked perfectly! My biggest list was 7700 lines long, and it took the macro about a minute to run. The same list now took less than two seconds.

    Problem solved!

    Thank you!!

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Select a range based on number next to range

    You're welcome!

    *Thanks for the rep!
    Last edited by xladept; 07-31-2017 at 05:51 PM.

+ 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. select range to negative column number
    By ccsmith in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-01-2016, 03:00 PM
  2. Select value based on a value being in a range
    By Nerdio in forum Excel General
    Replies: 3
    Last Post: 06-23-2014, 12:37 PM
  3. send to range, popup box to input what the range should be each time/select range
    By lax2734 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-26-2012, 01:37 AM
  4. [SOLVED] how to select a range and then add a specific number of cells after it
    By dwassner in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-03-2012, 08:41 AM
  5. select number range and copy to new tab?
    By papagorgio in forum Excel General
    Replies: 5
    Last Post: 08-26-2009, 11:08 AM
  6. Color Range Based On Number Range
    By ajocius in forum Excel General
    Replies: 1
    Last Post: 11-24-2006, 12:49 AM
  7. Select same range from large number of workbooks
    By BillC in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-18-2005, 05:06 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