On Aug 3, 1:30 pm, Tom Ogilvy <TomOgi...@discussions.microsoft.com>
wrote:
> Private Sub Worksheet_Change(ByVal Target As Range)
> 'DD Definecolumnstoautosortwhen record added or deleted
> If Target.Column = 13 Or Target.Column = 16 Then
> Columns(Target.Column).Resize(,3).Sort _
> Key1:=Cells(1, Target.Column), Order1:=xlAscending, _
> Header:=xlYes, OrderCustom:=1, _
> MatchCase:=False, Orientation:=xlTopToBottom
> End If
> End Sub
>
> --
> Regards,
> Tom Ogilvy
>
>
>
> "ssGuru" wrote:
> > I have code that autosorts ONE lookup column whenever a value is
> > entered.
>
> > What change would allow autosorting 3columnsof records but keep
> > everything ordered by the 1st column and not loose syncing of the
> > records?
>
> > This code perfectly sorts any values placed in col 13 OR 16 of some
> > lookup lists.
>
> > Private Sub Worksheet_Change(ByVal Target As Range)
> > 'DD Definecolumnstoautosortwhen record added or deleted
> > If Target.Column = 13 Or Target.Column = 16 Then
> > Columns(Target.Column).Sort _
> > Key1:=Cells(1, Target.Column), Order1:=xlAscending, _
> > Header:=xlYes, OrderCustom:=1, _
> > MatchCase:=False, Orientation:=xlTopToBottom
> > End If
> > End Sub
>
> > I couldn't find a Class property that delt with the issue of sorting
> >multiplecolumnsand keeping the records intact so I tried this code
> > change but it did nothing at all that I could see:
>
> > Private Sub Worksheet_Change(ByVal Target As Range)
> > 'DD Definecolumnstoautosortwhen record added or deleted
> > If Target.Column = 26 And Target.Column = 27 _
> > And Target.Column = 28 And Target.Column = 29 Then
> > Columns(Target.Column).Sort _
> > Key1:=Cells(1, Target.Column), Order1:=xlAscending, _
> > Header:=xlNo, OrderCustom:=1, _
> > MatchCase:=False, Orientation:=xlTopToBottom
> > End If
> > End Sub
>
> > Thanks, Dennis- Hide quoted text -
>
> - Show quoted text -
Thanks Tom,
Here is the code I ended up with that handles BOTH autosorting
selected single columns with headers OR autosorting the 1st column of
selected multiple colums (4wide and 3wide) with headers, while keeping
the records intact. Works perfectly.
This solves the issue of keeping the lookup lists perfectly sorted
regardless of changes made by the user.
Private Sub Worksheet_Change(ByVal Target As Range)
'DD Define multiple autosort cols when record added or deleted
If Target.Column = 5 Then
Columns(Target.Column).Resize(, 3).Sort _
Key1:=Cells(1, Target.Column), Order1:=xlAscending, _
Header:=xlYes, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom
End If
'DD Define multiple autosort cols when record added or deleted
If Target.Column = 13 Then
Columns(Target.Column).Resize(, 4).Sort _
Key1:=Cells(1, Target.Column), Order1:=xlAscending, _
Header:=xlYes, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom
End If
'DD Define single autosort cols when record added or deleted
If Target.Column = 9 Or Target.Column = 11 Then
Columns(Target.Column).Sort _
Key1:=Cells(1, Target.Column), Order1:=xlAscending, _
Header:=xlYes, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom
End If
End Sub