Juriemagic
07-28-2015, 11:49 PM
Hi good people!..
I have a code which I put together from recording macros, when I run the code the second half repeats. I have noticed that the sorting of the values also only sorts in the second round. The code is:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("AN2") = 0 Then
Exit Sub
End If
If Range("AN2") = 1 And Range("AN27") = 0 Then
MsgBox "No Records Found"
Range("AN2").FormulaR1C1 = 0
End If
If Range("AN2") = 1 And Range("AN27") = 1 Then
application.ScreenUpdating = False
Range("AO28:AO5028").Value = Range("AN28:AN5028").Value
Range("T28:AO5028").Select
ActiveWorkbook.Worksheets("COMPLETED WORK ORDERS").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("COMPLETED WORK ORDERS").Sort.SortFields.Add Key:= _
Range("AO28:AO5028"), SortOn:=xlSortOnValues, Order:=xlDescending, _
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("COMPLETED WORK ORDERS").Sort.SortFields.Add Key:= _
Range("T28:T5028"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
With ActiveWorkbook.Worksheets("COMPLETED WORK ORDERS").Sort
.SetRange Range("T28:AO5028")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
MsgBox "All Data Retrieved"
Range("AN2").FormulaR1C1 = 0
Range("E8").Select
End If
End Sub
Please help me to make the proper modification. All help will be greatly appreciated!
I have a code which I put together from recording macros, when I run the code the second half repeats. I have noticed that the sorting of the values also only sorts in the second round. The code is:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("AN2") = 0 Then
Exit Sub
End If
If Range("AN2") = 1 And Range("AN27") = 0 Then
MsgBox "No Records Found"
Range("AN2").FormulaR1C1 = 0
End If
If Range("AN2") = 1 And Range("AN27") = 1 Then
application.ScreenUpdating = False
Range("AO28:AO5028").Value = Range("AN28:AN5028").Value
Range("T28:AO5028").Select
ActiveWorkbook.Worksheets("COMPLETED WORK ORDERS").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("COMPLETED WORK ORDERS").Sort.SortFields.Add Key:= _
Range("AO28:AO5028"), SortOn:=xlSortOnValues, Order:=xlDescending, _
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("COMPLETED WORK ORDERS").Sort.SortFields.Add Key:= _
Range("T28:T5028"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
With ActiveWorkbook.Worksheets("COMPLETED WORK ORDERS").Sort
.SetRange Range("T28:AO5028")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
MsgBox "All Data Retrieved"
Range("AN2").FormulaR1C1 = 0
Range("E8").Select
End If
End Sub
Please help me to make the proper modification. All help will be greatly appreciated!