Solved

Sort data in excel spreadsheet

Posted on 2007-04-02
6
922 Views
Last Modified: 2013-12-25
How can I sort data in Excel spreadsheet through VB 6.0. I have the following code but it fails to sort the data.

optplot.Range(Cells(2, 8), Cells(Val(Me.Text1.Text) + 1, 10)).Select
optplot.Selection.Sort Key1:=optplot.Cells(2, 10), Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
oXL.DisplayAlerts = False

Than you for your help in advance.
0
Comment
Question by:Aiysha
  • 2
6 Comments
 
LVL 29

Expert Comment

by:Badotz
ID: 18837256
Do you get an error of some kind?
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 18837261
HI

As a bit of a newcomer myself I am not certain, but inserting a string for a cell address to replace text1.text fails for me so I assume it represents your problem.

Removing the superfluous optplot from the second line, (Selection.Sort Key1:=optplot.Cells(2, 10), Order1:=xlAscending, Header:=xlGuess etc.) results in a good sort so is this the problem?
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 18837721
Looks like I cut the wrong bit!!!

To be clear I suspect the line should be :

Selection.Sort Key1:=optplot.Cells(2, 10), Order1:=xlAscending, Header:=xlGuess etc.
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 18851445
Try this:

With optplot
    .Range(.Cells(2, 8), .Cells(Val(Me.Text1.Text) + 1, 10)).Select
    .Selection.Sort Key1:=.Cells(2, 10), Order1:=xlAscending, OrderCustom:=1
End With
oXL.DisplayAlerts = False

But in general, we need to see more of your code. You may not be connecting the Excel sheet at all.

Leon
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now