+ Reply to Thread
Results 1 to 4 of 4

Specify range based on cell contents?

  1. #1
    Registered User
    Join Date
    06-26-2008
    Location
    USA
    Posts
    19

    Specify range based on cell contents?

    I'm trying to create a macro that copies and sorts a table in 2 different places. I recorded a macro that did the trick at first but have come to the realization that since the ranges i recorded are static, than when i move the tables up or down one row they stop working.

    I therefore created 5 boxes which include the needed info to vary the range selection in the macro:
    Row Orig. Table Begins
    Column Orig Table Begins
    Last Row of 1st table
    Starting Column of 2nd table
    Starting Column of 3rd table

    I figured that if i had the data in these cells i could use them as a kind of variable range selection method that the macro would pull off of, but i'm unsure of how to incorporate them.

    This is the code with the static ranges:
    Please Login or Register  to view this content.
    Any ideas on how to make it possible to resize the arrays/ranges when something shifts?

  2. #2
    Valued Forum Contributor
    Join Date
    06-17-2009
    Location
    Chennai,India
    MS-Off Ver
    Excel 2003,excel 2007
    Posts
    678

    Re: Specify range based on cell contents?

    , than when i move the tables up or down one row they stop working.
    This is not clear. let us take an example . the data is like this with A1 having column heading and data from A2 down upto A10


    h1
    20
    26
    95
    29
    62
    6
    38
    80
    54

    now you select a table from A3 to A9 from the above range and you want to sort .
    another time you want to sort from A2 to A8. in this case do you want to sort with already sorted data or you want go back to original data and then select and sort.

    to sort a selected table in a range of data is first select and sort which can be done manually. if you want a macro why dont use this code statement

    Please Login or Register  to view this content.
    this appears to be trivial and so I think I have not understood your problem.

  3. #3
    Registered User
    Join Date
    08-04-2010
    Location
    Saudi Arabia
    MS-Off Ver
    Excel 2007
    Posts
    1

    Selecting ranges with different number of cells

    Hi.

    Can anyone please help.

    Here's my code:

    Sub transpose()
    Application.CutCopyMode = False
    Selection.Copy
    ActiveCell.Offset(0, 4).Range("A1").Select
    ActiveSheet.Paste
    Selection.End(xlToLeft).Select
    Selection.End(xlDown).Select
    Range(Selection, Selection.End(xlDown)).Select
    ActiveCell.Range("A1:B6").Select
    Application.CutCopyMode = False
    Selection.Copy
    Selection.End(xlUp).Select
    Selection.End(xlToRight).Select
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=True
    Selection.End(xlToLeft).Select
    Selection.End(xlToLeft).Select
    Selection.End(xlDown).Select
    Selection.End(xlDown).Select
    Application.CutCopyMode = False
    End Sub

    It is selecting the same number (6) of cells. I hope that it will select the range depending upon the number of cells with contents.

    I have attached a excel screenshot for better understanding.

    Please help.

    Thank you.
    Attached Images Attached Images

  4. #4
    Registered User
    Join Date
    06-26-2008
    Location
    USA
    Posts
    19

    Re: Specify range based on cell contents?

    Quote Originally Posted by venkat1926 View Post
    This is not clear. let us take an example . the data is like this with A1 having column heading and data from A2 down upto A10


    h1
    20
    26
    95
    29
    62
    6
    38
    80
    54

    now you select a table from A3 to A9 from the above range and you want to sort .
    another time you want to sort from A2 to A8. in this case do you want to sort with already sorted data or you want go back to original data and then select and sort.

    to sort a selected table in a range of data is first select and sort which can be done manually. if you want a macro why dont use this code statement

    Please Login or Register  to view this content.
    this appears to be trivial and so I think I have not understood your problem.

    The problem is that in my code won't work if the table is moved from the original location (say instead of AC14:AL80, it moves to BC15:BL81).
    The table as of now extends from column AC to column AL (with dates in AC and with percentages of performance by class in AD-AL). I want the macro to replicate the table twice and sort the replicated tables first by the first classes performance high-low (So essentially the entire rest of the table is tied to the sorting of the second column of table 2).

    The third table/second replicated is supposed to sort all columns from high-low, pegging the first and second column (since the dates should match up with column 2). That is what the loop in the code represents.
    Last edited by hgeek; 08-04-2010 at 01:37 PM. Reason: changed the text

+ 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