View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
[email protected] gojakie@gmail.com is offline
external usenet poster
 
Posts: 11
Default Creating xla file to clear junk and sort reqd data

The below code that you gave works well

Sub DelAndSort()
Range("A:A,C:C,E:F").Delete
Columns("A:B").Sort Key1:=Range("A2"), _
Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

But it does not satisfy my condition. I want my first sort on column
B. I changed the line .Sort Key1:=Range("A2") to "B2" and it still
works fine but if I add few more lines to my data, it does not give
desired output.

For instance, If I add the following to my data
Junk O Junk 10-C Junk Junk
Junk M Junk 10-A Junk Junk
Junk N Junk 10-B Junk Junk
Junk R Junk 10-F Junk Junk
Junk Q Junk 10-E Junk Junk
Junk P Junk 10-D Junk Junk

and make my data range bigger A1:F19 it sorts alphabetically. It does
not recognize numbers and text seperately.

If I run your code changing the sort key1 from A to B it give me the
following result

Code Remark
M 10-A
N 10-B
O 10-C
P 10-D
Q 10-E
R 10-F
A 1-A
B 1-B
C 1-C
D 1-D
E 1-E
F 1-F
G 2-A
H 2-B
I 2-C
J 2-D
K 2-E
L 2-F

But I want it in the following way (column A should not get sorted
first - first sort should always be on column B).

Code Remark
A 1-A
B 1-B
C 1-C
D 1-D
E 1-E
F 1-F
G 2-A
H 2-B
I 2-C
J 2-D
K 2-E
L 2-F
M 10-A
N 10-B
O 10-C
P 10-D
Q 10-E
R 10-F

I hope I made my question clear