![]() |
Expanding VBA to include more than one column
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 |
Expanding VBA to include more than one column
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. "Ken" wrote: 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 |
Expanding VBA to include more than one column
On Oct 2, 6:31 pm, JLGWhiz wrote:
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. "Ken" wrote: 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- Hide quoted text - - 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 |
All times are GMT +1. The time now is 07:35 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com