Link to home
Start Free TrialLog in
Avatar of Aiysha
AiyshaFlag for United States of America

asked on

Sort data in excel spreadsheet

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.
Avatar of Badotz
Badotz
Flag of United States of America image

Do you get an error of some kind?
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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