我在Excel中有一个客户表,我希望能够将新客户添加到该表的最后一行,而excel将自动对该表进行排序,以便该客户的名称将按字母顺序排序。
同样,该格式将与上一行相似。例如,第二列是DOB,因此我希望格式与上一行MM / DD / YYYY相同
谢谢
最佳答案
将随附的代码放入工作表模块中,它将自动对A列进行排序。
Private Sub Worksheet_Change(ByVal Target As Range)
'turn off updates to speed up code execution
With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
.DisplayAlerts = False
End With
If Not Intersect(Target, Columns(1)) Is Nothing Then
With ActiveSheet.Sort
.SetRange Range("A1:X" & Cells(Rows.Count, 1).End(xlUp).Row)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Columns("B").NumberFormat = "MM/DD/YYYY"
End If
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
.DisplayAlerts = True
End With
End Sub
关于excel - 自动排序和格式化以及Excel,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13020878/