944,121 Members | Top Members by Rank

Ad:
Nov 8th, 2004
0

Sorting a selection

Expand Post »
I have tried as many different ways to do a sort as I can think of... I keep getting application defined errors. Here is my code:

With ActiveSheet

.Range("a:a").Select
n = Application.CountA(Selection)

.Columns("B:B").Select
Application.CutCopyMode = False
Selection.TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, Semicolon:=False, Comma:=False, Space:=True, Other:=False, FieldInfo:=Array(1, 1), TrailingMinusNumbers:=True

(THE ABOVE PART WORKS)

.Columns("a1").Select
Selection.CurrentRegion.Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes,
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
(I GET APPLICATION DEFINED OR OBJECT DEFINED ERROR)
End With



I would appreciate any help..
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sandie is offline Offline
3 posts
since Nov 2004
Nov 8th, 2004
0

Re: Sorting a selection

Quote originally posted by sandie ...
I have tried as many different ways to do a sort as I can think of... I keep getting application defined errors. Here is my code:

With ActiveSheet

.Range("a:a").Select
n = Application.CountA(Selection)

.Columns("B:B").Select
Application.CutCopyMode = False
Selection.TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, Semicolon:=False, Comma:=False, Space:=True, Other:=False, FieldInfo:=Array(1, 1), TrailingMinusNumbers:=True

(THE ABOVE PART WORKS)

.Columns("a1").Select
Selection.CurrentRegion.Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes,
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
(I GET APPLICATION DEFINED OR OBJECT DEFINED ERROR)
End With



I would appreciate any help..
I'll be able to help if you post a sample of the data you're trying to sort.
Reputation Points: 16
Solved Threads: 1
Posting Whiz in Training
mnemtsas is offline Offline
200 posts
since Jul 2004
Nov 9th, 2004
0

Re: Sorting a selection

Quote originally posted by mnemtsas ...
I'll be able to help if you post a sample of the data you're trying to sort.
I am experiencing the same type of problem on code I have written before but now trying to put in a longer more extensive macro..

The entire code is:
Dim n As Integer


Worksheets("obssum").Activate
'delete any rows without a "class" or with a heading
Range("b:b").Select

Do Until ActiveCell.Offset(0, -1).Value = ""
If Len(ActiveCell.Value) = 1 Or ActiveCell.Value = "" Then
ActiveCell.EntireRow.Delete
Else
ActiveCell.Offset(1).Select
End If
Loop

'insert columns and add headings
Columns("C:C").Select
Selection.Insert Shift:=xlToRight
Selection.Insert Shift:=xlToRight
ActiveWindow.ScrollRow = 1
Range("C1").Select
ActiveCell.FormulaR1C1 = "Divison"
Range("D1").Select
ActiveCell.FormulaR1C1 = "Category"
Range("B2").Select

'count rows of worksheet
Range("a:a").Select
n = Application.CountA(Selection)

'Vloopup to add product class information
Range("c2").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC2,[prodclasslist.xls]Sheet1!R2C1:R385C5,2,false)"
Range("C2").Select
Selection.Copy
Range("D2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC2,[prodclasslist.xls]Sheet1!R2C1:R385C5,3,false)"
Range("D2").Select
Selection.Copy

Range("C2:d2").Select
Selection.Copy
ActiveWindow.LargeScroll Down:=-1

Range("C3:d" & n).Select
ActiveSheet.Paste
Application.CutCopyMode = False

Range("a1").Select
Selection.Columns.AutoFit

'
the data I am working with is:

A CLASS QTY INVVAL USAGE THISMO LASTMO CHG
100 25 677 5 0 0 0
100 25 677 5 0 0 0
100 B18 16 27631 106 2935 1481 -1454
100 B28 60 48734 453 0 0 0
100 B 76 76365 559 2935 1481 -1454
100 C0A 55 54437 143 8774 10131 1357
100 C00 179 224868 943 1381 1381 0
100 C10 135 233779 954 666 666 0
100 C11 26 449204 34 43337 35421 -7916
100 C13 8 72904 21 0 0 0
100 C2A 8 22972 6 9416 35017 25601
100 C20 17 82714 78 30775 30775 0
100 C30 4 4987 29 1209 1700 491
100 C5A 22 221681 171 24679 14675 -10004

I am trying to combine several macros onto one page -- this same code used to work before I tried this.

I am stumped as to why this is happening
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sandie is offline Offline
3 posts
since Nov 2004
Nov 9th, 2004
0

Re: Sorting a selection

Quote originally posted by mnemtsas ...
I'll be able to help if you post a sample of the data you're trying to sort.
actually I think I am having the problem due to combining my macros into a large program... I have worked through a few of the issues, but not sure I have them all worked out..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sandie is offline Offline
3 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Nested For Next Loops w/ Triangles
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: need help making something in VB





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC