+ Reply to Thread
Results 1 to 9 of 9

Use Cell Values to define and select a range

  1. #1
    Registered User
    Join Date
    06-19-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2010
    Posts
    40

    Use Cell Values to define and select a range

    Good afternoon - I'm working on a spreadsheet and I have run into a snag.

    I have used the concatenate function of Excel to determine a range of cells that I need to copy.

    In my workbook, the sheet with this information is called "Lists and References." The range I would like to select is on "Daily."

    In cells I42:I49, I have the ranges in the format Daily!W7:W20 - this indicates the selection I would like to copy onto another sheet, called "Show your Work." The values in the cells that identify the range I want to select come from the concatenate function.

    I'm stuck in VBA. Essentially, I want to use the values in the cell, for example I42, in my code for the range selection. Is there a very simple way to do this? If someone can help me get the range selected, then I can handle the rest. Thanks!

  2. #2
    Registered User
    Join Date
    06-19-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Use Cell Values to define and select a range

    Quote Originally Posted by WadeLair View Post
    Good afternoon - I'm working on a spreadsheet and I have run into a snag.

    I have used the concatenate function of Excel to determine a range of cells that I need to copy.

    In my workbook, the sheet with this information is called "Lists and References." The range I would like to select is on "Daily."

    In cells I42:I49, I have the ranges in the format Daily!W7:W20 - this indicates the selection I would like to copy onto another sheet, called "Show your Work." The values in the cells that identify the range I want to select come from the concatenate function.

    I'm stuck in VBA. Essentially, I want to use the values in the cell, for example I42, in my code for the range selection. Is there a very simple way to do this? If someone can help me get the range selected, then I can handle the rest. Thanks!

    I have cells with the beginning and the end ranges of the array - these are also in one column, if that helps.

  3. #3
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Use Cell Values to define and select a range

    WadeLair,

    Welcome to the forum!
    I think you're looking for something like this:
    Please Login or Register  to view this content.

    Alternate method:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  4. #4
    Registered User
    Join Date
    06-19-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Use Cell Values to define and select a range

    Thanks for the reply, but this doesn't do what I would like it to do. Thanks so much for your help, though.

    Range

    Daily!W7:W20
    Daily!AW7:AW20
    Daily!Y7:Y20
    Daily!AL7:AL20
    Daily!AM7:AM20
    Daily!AU7:AU20
    Daily!AV7:AV20
    Daily!B7:B20

    Here is the column with the values I would like to use for ranges.

    I want to take the ranges defined in the column, then copy them into another worksheet within my workbook.
    Last edited by WadeLair; 06-19-2012 at 04:22 PM.

  5. #5
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Use Cell Values to define and select a range

    WadeLair,

    The code supplied was meant to be used as starting point. The full code based on what you've described would look something like this. Change the Destination as needed.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    06-19-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Use Cell Values to define and select a range

    That is a little over my head! Thanks very much.

    So, if the destination for the values I copy is Show your Work!B30:O30, then, how does this line look?

    rng.Copy Destination:=Sheets("Show your Work").Cells(Rows.Count, "A").End(xlUp).Offset(1)

    ???

  7. #7
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Use Cell Values to define and select a range

    Now you're pasting a column (Daily!W7:W20) into a row ('Show your Work'!B30:O30). To do that, you'll need to use the .PasteSpecial method with Transpose:=True.

    Here's the updated code:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-19-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Use Cell Values to define and select a range

    Thanks again for all your hard work. This just isn't doing it for me.

    I'm thinking about a different approach, maybe it will be easier.

    OK - I have written a short function to give me the location of where certain text appears. Then, I use the LEN functions to remove the $, then I use concatenate to add in the name of the sheet where this is found and add the :. I may have made this too complicated, and I'm not sold on any of this. I do need the search capability because the text I'm searching for could be in different columns on the Daily! sheet.

    What if...We took the ranges identified below and named them as a function, then, just copied the function? Easier?


    Field Formatting Column Begin End Range
    Net Rooms Available $W$4 $W W W7 W20 Daily!W7:W20
    OOO Rooms $AW$4 $AW AW AW7 AW20 Daily!AW7:AW20
    Transient Rooms Sold $Y$5 $Y Y Y7 Y20 Daily!Y7:Y20
    Group Rooms Sold $AL$5 $AL AL AL7 AL20 Daily!AL7:AL20
    Group Rooms Available $AM$5 $AM AM AM7 AM20 Daily!AM7:AM20
    Arrivals $AU$4 $AU AU AU7 AU20 Daily!AU7:AU20
    Departures $AV$4 $AV AV AV7 AV20 Daily!AV7:AV20
    Arrival Date $B$4 $B B B7 B20 Daily!B7:B20


    Like for this, how could be define what we name TestFunction, based on what appears in these cells.


    ActiveWorkbook.Names.Add Name:="TestFunction", RefersToR1C1:= _
    "='Lists and References'!R44C16:R50C16"

    Application.Goto Reference:="TestFunction"
    Selection.Copy
    Range("R56").Select
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=True


    While loops are nice, I don't mind just adding the code for each one instead of completing the loop.

    Thanks,

  9. #9
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Use Cell Values to define and select a range

    At this point, if the code isn't able to be adapted to your specific needs, its probably time for:

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    To attach a workbook, click the Go Advanced button and then the Paper Clip icon to open the Manage Attachments dialogue.

+ 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