VBA codes

To whom it may concern,
I write a VBA code for Auto sorting the columns. I have problems with this. I define multiuser for it with their own passwords. so, I have to use protect sheet, protect workseet and protect and shared workbook. then, the code doesn’t work. what should am I do?
Also, I want to cut rows due to a specific word in one column to another workbook and delete the empty rows after cutting. how can I solve it?
My code is :
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 11 Or Target.Columns.Count > 1 Then _
If Target.Column <> 13 Or Target.Columns.Count > 1 Then _
If Target.Column <> 14 Or Target.Columns.Count > 1 Then _
If Target.Column <> 21 Or Target.Columns.Count > 1 Then _
Exit Sub
Dim tmp As Variant
tmp = Cells(Target.Row, 21).Formula ‘save contents
On Error GoTo Enable_Events
Application.EnableEvents = False
Cells(Target.Row, 21) = “#$”
Range(“K1”).Sort Key1:=Range(“K1”), Order1:=xlAscending, Header:=xlYes
Cells(Application.Match(“#$”, Columns(21), 0), 11).Select
Range(“M1”).Sort Key1:=Range(“M1”), Order1:=xlAscending, Header:=xlYes
Cells(Application.Match(“#$”, Columns(21), 0), 13).Select
Range(“N1”).Sort Key1:=Range(“N1”), Order1:=xlAscending, Header:=xlYes
Cells(Application.Match(“#$”, Columns(21), 0), 14).Select
Range(“U1”).Sort Key1:=Range(“U1”), Order1:=xlDescending, Header:=xlYes
Cells(Application.Match(“#$”, Columns(21), 0), 21).Select
Cells(Selection.Row, 21) = tmp ‘restore contents
Enable_Events:
Application.EnableEvents = True
End Sub
 

By: Neda

Leave a Reply

Your email address will not be published. Required fields are marked *