|
以下是我录制的代码,对一张工作表中的数据进行自定义排序,但是行数是固定的,我的工作表经常会有改动,增加行数,或者是减少行数,这样就要每次都要修改行数的区域,例如A1:J107,I2:I107, 请问有什么办法自动识别有效行数后,然后进行自定义排序么?
Windows("必备药物库存情况.xlsx").Activate
Sheets("必备保障品种明细").Select
Range("I4").Select
ActiveWorkbook.Worksheets("必备保障品种明细").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("必备保障品种明细").Sort.SortFields.Add(Range("I2:I107"), _
xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, 0 _
, 0)
ActiveWorkbook.Worksheets("必备保障品种明细").Sort.SortFields.Add(Range("I2:I107"), _
xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, _
192, 0)
ActiveWorkbook.Worksheets("必备保障品种明细").Sort.SortFields.Add(Range("I2:I107"), _
xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(146, _
208, 80)
ActiveWorkbook.Worksheets("必备保障品种明细").Sort.SortFields.Add Key:=Range( _
"I2:I107"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("必备保障品种明细").Sort
.SetRange Range("A1:J107")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Columns("I:I").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("I16").Select
Sheets("KC").Select
Application.CutCopyMode = False
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Sheets("必备保障率汇总").Select
Range("F2:F8").Select
ChDir "E:\(Ⅰ)保障率\必备保障率\10月份"
ActiveWorkbook.SaveAs Filename:="E:\(Ⅰ)保障率\必备保障率\10月份\必备药物库存情况_" & Format(Date$, "yyyymmdd") & ".xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
End Sub
|
|