Column sorting

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to be able to re-sort two columns of information every time I make a
new entry. I want it to start in alphabetical order in the first column and
finish off evenly in the second. ex:

column A Column B
a e if I make an entry to column
A (f), I want the
b g program to sort it and place
it in column B
c h between the e and g. It
needs to resize the
d columns and make both column
entries equal.
f
 
Try this:

Sub ABCDEF()
'Set the two columns here as Col1 and Col2
Const Col1 = "A"
Const Col2 = "B"
Dim LastRow As Long, NextRow As Long
LastRow& = Range(Col2 & Rows.Count).End(xlUp).Row
NextRow& = Range(Col1 & Rows.Count).End(xlUp).Row + 1
Range(Col2 & "1:" & Col2 & LastRow&).Cut _
Destination:=Range(Col1 & NextRow&)
Range(Col1 & NextRow&).Select
Columns(Col1 & ":" & Col1).Select
Selection.Sort Key1:=Range(Col1 & "1"), Order1:=xlAscending, _
Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
LastRow& = Range(Col1 & Rows.Count).End(xlUp).Row
Range(Col1 & (CInt(LastRow& / 2) + 1) & ":" & Col1 & LastRow&).Cut _
Destination:=Range(Col2 & "1")
Range(Col2 & "1").Select
End Sub

No provision was made for column headings.

Hope this helps,

Hutch
 
Tom Hutchins said:
Try this:

Sub ABCDEF()
'Set the two columns here as Col1 and Col2
Const Col1 = "A"
Const Col2 = "B"
Dim LastRow As Long, NextRow As Long
LastRow& = Range(Col2 & Rows.Count).End(xlUp).Row
NextRow& = Range(Col1 & Rows.Count).End(xlUp).Row + 1
Range(Col2 & "1:" & Col2 & LastRow&).Cut _
Destination:=Range(Col1 & NextRow&)
Range(Col1 & NextRow&).Select
Columns(Col1 & ":" & Col1).Select
Selection.Sort Key1:=Range(Col1 & "1"), Order1:=xlAscending, _
Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
LastRow& = Range(Col1 & Rows.Count).End(xlUp).Row
Range(Col1 & (CInt(LastRow& / 2) + 1) & ":" & Col1 & LastRow&).Cut _
Destination:=Range(Col2 & "1")
Range(Col2 & "1").Select
End Sub

No provision was made for column headings.

Hope this helps,

Hutch
Thanks for the info. Hutch. I need to explain that I am not well versed in
Excel therefore I really do not know how to use the formula you provided.
Can you start me off? Better yet can you provide me with an excel
spreadsheet with examples and all I have to do is substitute my information.
My e-mail is (e-mail address removed)
Thanks again for your effort and time.
 
ukyob said:
Thanks for the info. Hutch. I need to explain that I am not well versed in
Excel therefore I really do not know how to use the formula you provided.
Can you start me off? Better yet can you provide me with an excel
spreadsheet with examples and all I have to do is substitute my information.
My e-mail is (e-mail address removed)
Thanks again for your effort and time.

Thanks for the reply. I should have known that the formula was a macro. I
just was not thinking. The program works beautifully. Thanks again for your
time and effort.
 
Back
Top