Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) '用户在的[C1:H1]区间双击任意一个单元格,电脑将对该单元格所在的列进行有标题行的降序排列 If Target.Count > 1 Then Exit Sub '如果单元格个数超过1个,则退出程序 If Target.Row <> 1 Then Exit Sub '如果单元格行数不在第一行,则退出程序 If Target.Column > 8 Or Target.Column < 3 Then Cells.Interior.ColorIndex = xlNone Exit Sub '第3列到第8列之间的数据 End If '有标题行一个条件降序排序 Dim Myr& Dim Sht1 As Worksheet Set Sht1 = ThisWorkbook.Worksheets("B") Application.ScreenUpdating = False Cancel = True Cells.Interior.ColorIndex = xlNone Target.Interior.Color = RGB(0, 0, 255) Myr = Sht1.[a65536].End(xlUp).Row Sht1.Range("a1:h" & Myr).Sort Key1:=Sht1.Cells(1, Target.Column), Order1:=xlDescending, Header:=xlYes, _ OrderCustom:=2, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _ :=xlPinYin ', DataOption1:=xlSortNormal '加这一句电脑就会提示"应用程序定义或对象定义错误" Application.ScreenUpdating = True 'End If End Sub |