+ Reply to Thread
Results 1 to 13 of 13

Excel formula to manage output orientation

Hybrid View

  1. #1
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Excel formula to manage output orientation

    This macro will alphabetize the student roster, if it's not already, and uses a "one pass per student" loop that should be peppy on larger data sets since you're not going cell by cell. Also, your sample didn't show data in row1, so mine adds a title row. We can delete that if there are titles already.

    Sub ReorganizeStudents()
    Dim LC As Long, i As Long, wsOut As Worksheet
    Application.ScreenUpdating = False
    Set wsOut = Sheets("Sheet2")
    
    Rows(1).Insert xlShiftDown
    Range("A1") = "key"
    
    Range("A:A").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("AA1"), Unique:=True
    Range("AA:AA").Sort Key1:=Range("AA2"), Order1:=xlAscending, Header:=xlYes, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
    Range("AA2:AA" & Rows.Count).SpecialCells(xlCellTypeConstants).Copy
    wsOut.Range("A1").PasteSpecial xlPasteAll, Transpose:=True
    Range("AA:AA").Clear
    
    LC = wsOut.Cells(1, Columns.Count).End(xlToLeft).Column
    
    For i = 1 To LC
        Range("A:A").AutoFilter 1, wsOut.Cells(1, i)
        Range("B2", Range("B2").End(xlDown)).Copy wsOut.Cells(2, i)
    Next i
    
    ActiveSheet.AutoFilterMode = False
    Rows(1).Delete xlShiftUp
    wsOut.Activate
    Application.ScreenUpdating = True
    End Sub
    How/Where to install the macro:

    1. Open up your workbook
    2. Get into VB Editor (Press Alt+F11)
    3. Insert a new module (Insert > Module)
    4. Copy and Paste in your code (given above) to this new module
    5. Get out of VBA (Press Alt+Q)
    6. Save your sheet

    The macro is installed and ready to use. Press Alt-F8 and select it from the macro list.

    Will create the list on Sheet2. Works well on your sample sheet.
    Last edited by JBeaucaire; 02-09-2010 at 02:45 AM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ 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