Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 2nd, 2010, 02:29 PM
Registered User
 
Join Date: Jul 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sorting Data Dynamically???

OK, I'll take my best shot at explaining what I'm trying to do. I'm working on a project for my aunt. I've been successful at everything except sorting the data. I have five columns of data, three of which are dates for deadlines and the other two are markers to show which deadlines have been met.

I've tried using nested for loops for each of the date columns to select a row if that deadline hasn't been met, then insert it where it goes. Once the left date column is sorted I move to the next date column and repeat. Likewise for the third date column.
My code looks like this:
Code:
 
For I = 2 To LastRow Step 1
        If oSH.Cells(I, 7).Value = Empty And oSH.Cells(I, 9) = Empty Then
            For J = 2 To LastRow Step 1
                If Cells(I, 6).Value <= Cells(J, 6).Value And I > J Then
                    Cells(J, 1).EntireRow.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
                    Cells(I + 1, 1).EntireRow.Copy Destination:=Cells(J, 1).EntireRow
                    Cells(I + 1, 1).EntireRow.Delete Shift:=xlUp
                End If
            Next J
        End If
Next I
This doesn't exactly work because I get a date of 03/15/2010 ahead of 03/11/2010 in the righthand column.

Two questions: 1) Is there a better way to do what I'm trying to do? 2)If not, what am I missing in the existing code?

I can send examples of my sheet if need be.


Thanks,
Justin
 
Old January 3rd, 2010, 11:08 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

MMMM.. you know that excel has a built in sort option??

Also, to see it work in code, just record a macro that do what you need and then use it.

Also, take in mind that to sort dates, the best way is to use them in the form of YYYYMMDD
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old January 4th, 2010, 05:21 PM
Registered User
 
Join Date: Jul 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, as engineers often do - I overcomplicated the issue. I may as well have tried to turn 2 + 2 into a differential equation. Anway, issue resolved.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting sql data bex ASP.NET 3.5 Basics 0 March 17th, 2009 06:36 PM
Data sorting dilipv .NET Framework 2.0 1 March 10th, 2008 09:19 AM
need to Dynamically group sorting ??? kspiderman Crystal Reports 3 May 24th, 2005 03:55 PM
sorting retrieved data don baroo Classic ASP Basics 2 November 23rd, 2004 08:31 AM
Sorting Data seidici Excel VBA 2 May 21st, 2004 02:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.