PDA

View Full Version : Solved: VBA Sort using the Left 7 Charaters



JimS
02-25-2009, 01:28 PM
I'm using the following VBA to Sort on Column - A and then Column - B.

Range("OT").Select
Selection.Sort Key1:=Range("A10"), Order1:=1, Key2:=Range("B10"), _
Order2:=1, Header:=1, OrderCustom:=1, MatchCase:=0, _
Orientation:=1, DataOption1:=1, DataOption2:=0

Can it be modified to Sort on Column - A and then only use the first 7 charaters of Column - B.

Thanks for any and all help.

Jim

Bob Phillips
02-25-2009, 02:35 PM
Columns(3).Insert
With Range("C10").Resize(Range("B10").End(xlDown).Row)
.Formula = "=LEFT(B10,7)"
.Value = .Value
End With
Range("OT").Sort Key1:=Range("A10"), Order1:=1, _
Key2:=Range("C10"), Order2:=1, _
Header:=1, OrderCustom:=1, _
MatchCase:=0, Orientation:=1, _
DataOption1:=1, DataOption2:=0
.Columns(3).Delete

Kenneth Hobs
02-25-2009, 02:36 PM
Have the code insert a column B and insert those characters from the original column B, sort and then delete the temporary column.

Is Bob fast or what?

JimS
02-25-2009, 07:15 PM
Thanks to both of you...