Expanding VBA to include more than one column

  • Thread starter Thread starter Ken
  • Start date Start date
K

Ken

Hi Group,
Please excuse a small repost of a question that I had on another
group....it has to do with some VBA that will auto sort a list after a
new item is typed in....I have 4 or 5 columns that have a drop down,
with lists on a seperate page in the workbook....I have tried several
things, but since I know nothing about what I'm doing, I got myself in
just a little too deep...the code is this:

Option Explicit


Private Sub Worksheet_Change(ByVal Target As Range)
Columns(1).Sort Key1:=Range("A1"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom
End Sub


I can sort other lists by creating a new page for each list, but it
adds a few pages to the workbook...can the code above be written to
include a list in C1, E1, F1...etc, on the same sheet? I tried
=Range("A1","C1", "E1", "F1"}, but I still just get column A to
sort...any ideas will truly be appreciated...Thanks in Advance!
Ken
 
Give this a try:

Private Sub Worksheet_Change(ByVal Target As Range)
Columns(Target.Column).Sort Key1:=Cells(1, Target.Column) _
, Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1 _
, MatchCase:=False, Orientation:=xlTopToBottom
End Sub

You might need to put all that on one line if the attenuation bar isn't in
there correctly.
 
Give this a try:

Private Sub Worksheet_Change(ByVal Target As Range)
Columns(Target.Column).Sort Key1:=Cells(1, Target.Column) _
, Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1 _
, MatchCase:=False, Orientation:=xlTopToBottom
End Sub

You might need to put all that on one line if the attenuation bar isn't in
there correctly.








- Show quoted text -

JLGWhiz,
That works perfectly on a test sheet.....I'll get that on my
worksheet and give it a try, although I have no doubt it will work!!
Thank you so much for your help!
Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top