| | |
Sorting a selection
![]() |
•
•
Join Date: Nov 2004
Posts: 3
Reputation:
Solved Threads: 0
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..
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..
•
•
•
•
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..
Mark Nemtsas
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
•
•
Join Date: Nov 2004
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by mnemtsas
I'll be able to help if you post a sample of the data you're trying to sort.
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
![]() |
Similar Threads
- Question about a simple sorting method without arrays (C++)
- Picture and Video files have been deleted by system!!! HELP!!! (Viruses, Spyware and other Nasties)
- Produce output (C++)
- selection sorting issues (C)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Nested For Next Loops w/ Triangles
- Next Thread: Com5 without MSComm
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





