Solved

Sort data in excel spreadsheet

Posted on 2007-04-02
6
924 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

776 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