A Screenshot of the worksheet is attached below. Help needed please as I'm new to using codes in VBA.
https://1drv.ms/u/s!AuJosJM5re-thDoADN_0odaoTIQH
https://1drv.ms/u/s!AuJosJM5re-thDoADN_0odaoTIQH
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim rw As Long
' Only run if a single cell is updated
If Target.CountLarge > 1 Then Exit Sub
' Exit if update not in columns C, D, or E
If Intersect(Target, Range("C:E")) Is Nothing Then Exit Sub
' Exit if update above column 5
If Target.Row <= 5 Then Exit Sub
' Check to see if values in columns C, D, and E
rw = Target.Row
If Len(Cells(rw, "C")) > 0 And Cells(rw, "D") > 0 And Cells(rw, "E") > 0 Then
Application.EnableEvents = False
Call MySort
Application.EnableEvents = True
End If
End Sub
Sub MySort()
Dim lastRow As Long
' Find lastRow with data in column C
lastRow = Cells(Rows.Count, "C").End(xlUp).Row
' Sort results by columns D then E
Range("C5:Q" & lastRow).Sort _
key1:=Range("D5"), order1:=xlAscending, _
key2:=Range("E5"), order2:=xlAscending, Header:=xlYes
End Sub
If Len(Cells(rw, "C")) > 0 And Cells(rw, "D") > 0 And Cells(rw, "E") > 0 Then
Len(Cells(rw, "C")) > 0
Cells(rw, "D") > 0
That is text. Note that text can contain numbers. As matter as fact, text can be all numbers (if you format the the cell as Text before entry). Things like Zip Codes and Social Security Numbers, which may contain leading zeroes fall into this category.Also what code to use for lines that have both Text and Numbers e.g SD5 or MR12
' Exit if update not in columns C, D, or E
If Intersect(Target, Range("C:E")) Is Nothing Then Exit Sub