Question

Advanced Sort Operation

Asked by: slow1000

I have a list of data in arranged in columns that I want to sort by how many rows are actually present (non-blank values).  

I have a header row, with ten data rows beneath.  I need to preserve the columns, and just sort the columns by how many values are actually present below the title.  (All ten values present at left and rightward to all values missing).

Thanks for any help,
Sam

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-04-25 at 15:59:23ID21827398
Tags

sort

Topic

Microsoft Excel Spreadsheet Software

Participating Experts
3
Points
500
Comments
14

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Sort Top Ten Values
    I have 1 Table with 50,000 rows and growing. I need to sort one column and only display the top ten results, ie Ten Highest values. I am using Oracle 8. I have tried the following but it takes over 15 minutes to finish. select rad_user, rad_sessiontime from rad XXX where 10...
  2. SAM errors
    A few monthes ago our main file server's main hard drive failed. We replaced it and since reinstalling everything and restoring our backup <which we do every night> we have been getting this. We have a second Windows 2000 Server that is also running Exchange 2000. And...
  3. Corrupt SAM database
    I have a non-booting installation of Windows XP Home edition I'm currently working on. I am trying to access the Recovery Console, but once I press 'enter' after entering the number of the desired Windows installation, it locks up before asking for the administrator password...
  4. Arranging alphanumeric values in a cell
    Hi all Anybody got an idea if there is a function that I could write to arrange data alphabetically. e.g. Cell A1 has the data as CBA B1 would have a function that would convert it to ABC Cell A2 has EHABZ B2 converts to ABEHZ and so on...... Any help much appreciated. R...
  5. Server SID/SAM Transfer
    I've got a "semi-unstable" old installation of SERVER on DOMAIN which I want to replace with a fresh hardware box to also be called SERVER on DOMAIN. What is the process for copying the SIDs/SAMs/etc. information from the old SERVER to the new SERVER so that I can ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: FlysterPosted on 2006-04-25 at 20:07:11ID: 16540734

Not quite sure what you are trying to acomplish. If you want to sort the left colmn, and have the columns sort too, you can use the following macra:

Sub SortColumnMacro()

    Range("A2:A11").Select
    Range("A1:E11").Sort Key1:=Range("A2"), Order1:=xlAscending, Header:= _
        xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
End Sub

The first line selects the ten rows below your header. The second defines the range of columns to the left. Just adjust to the columns you need.

Flyster

 

by: slow1000Posted on 2006-04-25 at 23:45:59ID: 16541479

Paste this into Excel as is to see:

year      Value1      Value2      Value3      Value4      Value5      Value6      Value7      Value8      Value9
2005      2.51      2.42      2.84      2.02      2.77      2.92      8.80      8.71      2.16
2004            2.50      2.70      2.00      2.50      3.10      8.80      8.40      1.90
2003            2.50      2.60      1.80      2.50      3.00      8.80      8.00      1.80
2002            2.50            1.70      2.80            8.60      7.80      2.00
2001                              3.50            8.50      7.80      2.00
2000                        1.70      3.50      2.50      8.30      7.70      1.50
1999            2.30                  3.00      2.50      8.70      7.60      1.70
1998                              3.00            8.70      7.50      
1997                              2.81            8.86      7.61      
1996                              3.41            8.60      7.59      

Basically, I want to order the values by how many years of data are actually present, so Values 5,7,8 would be sorted to the left, but value 1, which only has one year of data, should be to the extreme right.

 

by: slow1000Posted on 2006-04-25 at 23:52:08ID: 16541497

I can do this by using the function countblank, then filling and sorting horizontally by the countblank row (ascending), but my extant is extremely large, so I'm looking for a macro to do it more easily.

 

by: patrickabPosted on 2006-04-26 at 01:57:36ID: 16541974

slow1000,

You can't 'sort' horizontally using the ordinary sort function. Sort works by rows not columns.

You will need a macro to do this.

Patrick

 

by: roryaPosted on 2006-04-26 at 05:03:04ID: 16542921

Patrick,
If you choose Data-Sort from the Menu, there is an options button (at least in later versions of Excel; I can't recall if it has always been there) and one of the options is to sort Left to Right.

 

by: roryaPosted on 2006-04-26 at 05:04:55ID: 16542935

Sam,
Would it be OK for the macro to create the countblank formula for each column and then sort on that (it can be cleared afterwards if you like) or do you want to avoid that?

 

by: patrickabPosted on 2006-04-26 at 05:17:20ID: 16543009

rorya - Thank you for that. By now I should know that - but I do now! - Patrick

 

by: roryaPosted on 2006-04-26 at 05:26:52ID: 16543072

Patrick,
No problem - I guess this is why Office 12 is getting such a big makeover of the toolbars! (if I had £1 for every feature I've ever overlooked, I'd be a rich man! :-}
Rory

 

by: patrickabPosted on 2006-04-26 at 05:34:35ID: 16543125

slow1000,

Here's the sorting sub:

Sub sorted()
    Dim rng As Range
    Dim rowes As Integer
    Dim colms As Integer
    Dim r As Integer
    Dim c As Integer
    Dim counter As Integer
   
    rowes = [a65536].End(xlUp).Row - 1
    colms = [iv1].End(xlToLeft).Column - 1
    counter = 0
   
    For c = 2 To colms + 1
        For r = 2 To rowes + 1
            If IsNumeric(Cells(r, c)) = True And Cells(r, c) <> "" Then
                counter = counter + 1
            End If
        Next r
        Cells(rowes + 2, c) = counter
        counter = 0
    Next c

    Set rng = Range(Cells(2, 2), Cells(rowes + 2, colms + 1))
    rng.Select
    Selection.Sort Key1:=Range("B" & rowes + 2), Order1:=xlDescending, Header:=xlGuess _
        , OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
        DataOption1:=xlSortNormal
    Rows(rowes + 2).ClearContents
    [B2].Select
End Sub

Patrick

 

by: patrickabPosted on 2006-04-26 at 05:45:54ID: 16543214

It should be this - to include the column headers:

Sub sorted()
    Dim rng As Range
    Dim rowes As Integer
    Dim colms As Integer
    Dim r As Integer
    Dim c As Integer
    Dim counter As Integer
   
    rowes = Sheets(2).[a65536].End(xlUp).Row - 1
    colms = Sheets(2).[iv1].End(xlToLeft).Column - 1
    counter = 0
   
    For c = 2 To colms + 1
        For r = 2 To rowes + 1
            If IsNumeric(Cells(r, c)) = True And Cells(r, c) <> "" Then
                counter = counter + 1
            End If
        Next r
        Cells(rowes + 2, c) = counter
        counter = 0
    Next c

    Set rng = Range(Cells(1, 2), Cells(rowes + 2, colms + 1))
    rng.Select
    Selection.Sort Key1:=Range("B" & rowes + 2), Order1:=xlDescending, Header:=xlGuess _
        , OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
        DataOption1:=xlSortNormal
    Rows(rowes + 2).ClearContents
   
End Sub

Patrick

 

by: patrickabPosted on 2006-04-26 at 05:53:57ID: 16543273

slow1000,

OK, here it is all working together:

http://my.storenow.net?f=508

Hope it does what you want.

Patrick

 

by: slow1000Posted on 2006-04-26 at 08:38:28ID: 16544900

Thanks for the input, everybody. Patrick, it worked well once again.

Patrick, I am now officially done with using Excel, and am now back to SAS (another fun language, but at least I'm competent with it), so no more MS Office question.  Anyway, the data I'm working with was stretching the limits of Excel in terms of sheer size.

 

by: patrickabPosted on 2006-04-26 at 11:43:37ID: 16546882

slow1000 - Thanks for the grade. Good luck with SAS - that last company that I knew of that adopted SAS amid much blowing of trumpets, was closed within 6 months of installing it! So I hope you fare better. - Patrick

 

by: slow1000Posted on 2006-04-26 at 21:33:15ID: 16550146

Patrick,
Unfortunately, I will have no such luck as to get away from SAS--I normally work with huge datasets and odd statistical and econometric methods.  Only Stata really can beat out SAS for doing what I do, but it's not as versatile in other areas, so I'm stuck with SAS until the next big thing comes out, but I'm not holding my breath.  I just happenned to be working on a project using Eviews, which is quite picky about how it wants data, so I needed the data cleaned up before importing it, and Excel is what I have at home.  Next stop, fun with ESRI's Arcview for a consulting project, then Gauss this fall.
Sam

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...