Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-06-2014, 03:18 AM
macropod's Avatar
macropod macropod is offline Need help sorting data in columns that will sort by number of Xs Windows 7 32bit Need help sorting data in columns that will sort by number of Xs Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Kevin,



Interesting approach but, given the OP's 'real' workbook as 100+ columns of data, doubling that number might make the workbook rather unwieldy. Plus it still doesn't sort the data - it just gives a ranked report of them. It that were all that's required, I'd be inclined to use a separate worksheet and arrange the data in a single column.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #2  
Old 04-06-2014, 05:26 AM
Kevin@Radstock Kevin@Radstock is offline Need help sorting data in columns that will sort by number of Xs Windows 8 Need help sorting data in columns that will sort by number of Xs Office 2013
Office 365
 
Join Date: Feb 2012
Posts: 94
Kevin@Radstock is on a distinguished road
Default

Hi macropod

Sorry, misread the post and missed the other sheet with their example!!

Attached another version, I will have another go in the week, to see if I can shorten the formulas.
Attached Files
File Type: xlsx 005-Poll Results for Excel Forum_Rev1.xlsx (19.3 KB, 10 views)
Reply With Quote
  #3  
Old 04-06-2014, 02:02 PM
jolivanes jolivanes is offline Need help sorting data in columns that will sort by number of Xs Windows XP Need help sorting data in columns that will sort by number of Xs Office 2007
Advanced Beginner
 
Join Date: Sep 2011
Posts: 91
jolivanes will become famous soon enough
Default

Or try this (on a copy of your workbook)
When you copy it into another workbook, change the Sheet references as required.
Code:
 
Sub Try_This()
    Dim lc As Long, lr As Long, i As Long, c As Range
    lc = Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
    lr = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Application.ScreenUpdating = False
    With Range(Cells(1, 1), Cells(lr, lc))
        .SpecialCells(4).Delete -4162
    End With
    For i = 1 To lc
        Cells(i, lc + 1).Value = ActiveSheet.Cells(Rows.Count, i).End(xlUp).Row
        Cells(i, lc + 2).Value = i
    Next i
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range(Cells(1, lc + 1), Cells(lc, lc + 1)), _
        SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").Sort
        .SetRange Range(Cells(1, lc + 1), Cells(lc, lc + 2))
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    i = 1
    For Each c In Range(Cells(1, lc + 2), Cells(1, (lc + 2)).End(xlDown))
        Range(Cells(1, c.Value), Cells(1, c.Value).End(xlDown)).Copy Cells(lr + 2, i)
        i = i + 1
    Next c
    Rows("1:" & lr + 1).EntireRow.Delete
    Application.ScreenUpdating = True
End Sub
Attached Files
File Type: xlsm Poll Results for Excel Forum VS 1.xlsm (22.5 KB, 8 views)
Reply With Quote
  #4  
Old 04-07-2014, 03:30 PM
jolivanes jolivanes is offline Need help sorting data in columns that will sort by number of Xs Windows XP Need help sorting data in columns that will sort by number of Xs Office 2007
Advanced Beginner
 
Join Date: Sep 2011
Posts: 91
jolivanes will become famous soon enough
Default

This is better.
Make sure you save your workbook as macro enabled (.xlsm) after copying the code into it,
Code:
 
Sub Try_This_A()
    Dim lc As Long, lr As Long
    lc = Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
    lr = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Application.ScreenUpdating = False
    With Range(Cells(1, 1), Cells(lr, lc))
        .SpecialCells(4).Delete -4162
    End With
    Rows("1:1").Insert Shift:=xlDown
    Range(Cells(1, 1), Cells(1, lc)).FormulaR1C1 = "=COUNTA(R[2]C:R[15]C)"
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range(Cells(1, 1), Cells(1, lc)), _
        SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").Sort
        .SetRange Range(Cells(1, 1), Cells(lr + 1, lc))
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlLeftToRight
        .SortMethod = xlPinYin
        .Apply
    End With
    Rows("1:1").Delete
    Application.ScreenUpdating = False
End Sub
Reply With Quote
  #5  
Old 04-11-2014, 09:01 PM
jolivanes jolivanes is offline Need help sorting data in columns that will sort by number of Xs Windows XP Need help sorting data in columns that will sort by number of Xs Office 2007
Advanced Beginner
 
Join Date: Sep 2011
Posts: 91
jolivanes will become famous soon enough
Default

@brenna.at.work
Did you get your workbook to work with any of the solutions offered?
Reply With Quote
  #6  
Old 04-12-2014, 07:00 AM
Kevin@Radstock Kevin@Radstock is offline Need help sorting data in columns that will sort by number of Xs Windows 8 Need help sorting data in columns that will sort by number of Xs Office 2013
Office 365
 
Join Date: Feb 2012
Posts: 94
Kevin@Radstock is on a distinguished road
Default

Quote:
Originally Posted by jolivanes View Post
@brenna.at.work
Did you get your workbook to work with any of the solutions offered?
Probably a cross poster and got their answer elsewhere!
Reply With Quote
Reply

Tags
data, probz, sorting



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help sorting data in columns that will sort by number of Xs Cannot Convert Text Cell to number format to be able to sort the data jyfuller Excel 10 06-19-2013 05:31 PM
Need help sorting data in columns that will sort by number of Xs How to sort table having three columns? Bahir Barak Word 2 01-20-2011 01:52 PM
Can I do this? sorting data in seperate columns shumonsaha Excel 0 07-04-2010 03:05 AM
CAUTION!! Sorting a spreadsheet with hidden columns will trash your data. psmaster@earthlink.net Excel 0 11-24-2009 11:54 AM
Sorting columns in Excel - please advise Jonre Excel 2 08-21-2009 02:38 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:39 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft