+ Reply to Thread
Results 1 to 13 of 13

Range selection

  1. #1
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Thumbs up Range selection

    Hi all, first I'll submit the code and describe the problem following the code.

    First, this code works:
    Please Login or Register  to view this content.
    Second, this code does not work:
    Please Login or Register  to view this content.
    I am relatively new to VBA and do not understand the difference here, other than selecting rows instead of columns. Any advice?

    Thanks so much!
    Attached Files Attached Files
    Last edited by Mordred; 07-21-2010 at 05:09 PM.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Range selection

    You are telling it to select a cell 24 rows up. If you are not on a cell that is lower than row 24, it will try to select a cell with row number 0 or -integer, which will result in an error. What cell are you starting in, and what cell do you expect it to select?

    BTW, usually you can refer to cells without selecting them at all. It makes for much more efficient code.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Range selection

    Ok, I see what you are seeing. I did a type error (I should have copy/pasted the code). Here it is:
    Please Login or Register  to view this content.
    The active cell is at "C8"

  4. #4
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Range selection

    The Resize Property's arguments describe how many rows and columns will be in your range once the code runs. You can't have -24 rows and 0 columns.

  5. #5
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Range selection

    Ok, I get that. So, does that mean I will have to do a Do While Loop to select and then copy each cell in that range?

  6. #6
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Range selection

    Hard to say based on your given information. What are you trying to do?

  7. #7
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Range selection

    Basically, I'm trying to take source data, copy it to one worksheet, clean and organize the data, and then copy/paste it into our original worksheet. I'm trying to improve the process of data input. I've uploaded the file.

    The source data is loaded into the "InsertSheet". From there, I'm trying to get the chosen data, using the find method, into the "LookTbl" sheet. Once the data is all in the right position, it will go to its permanent cells in "IndMthly" sheet. I could probably skip sending the data into the "LookTbl" but not until it is all figured out. Thanks by the way for your time.

  8. #8
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Range selection

    It looks like your upload didn't work right.

    I really just meant, what are you trying to do with that line of code?

  9. #9
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Range selection

    All I am trying to do with that code is select a range of data.

  10. #10
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Range selection

    What range?

  11. #11
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Range selection

    The range 24 cells down from my active cell. The range isn't defined and cannot be.
    So:

    If ActiveCell is at C8, I need the range from C8:C32. But I can't use

    Please Login or Register  to view this content.
    because the code will continuously go to that range, instead of selecting the range 24 cells down from the active cell.

    Does this make sense?
    Last edited by Mordred; 07-21-2010 at 05:02 PM.

  12. #12
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Range selection

    Like this?

    Please Login or Register  to view this content.
    Or like this?

    Please Login or Register  to view this content.

  13. #13
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Range selection

    Haha, I love how you pros make a daunting task so easy. Yes,

    Please Login or Register  to view this content.
    works like a charm.

    Thank you so much.

+ 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