我有一个电子表格,这里有一小段:
理想情况下,当我向colc添加一个日期时,不同的列会自动将日期填充到最后一行的截止日期。这是我的代码(其中也包含一些排序内容,工作正常);在我定义
lastDrag
我认为问题在于:
Private Sub Worksheet_Change(ByVal Target As Range)
'On Error Resume Next
Dim firstRow As Long
Dim insRow As Long
Dim lastRow As Long
If Not Intersect(Target, Range("A:AC")) Is Nothing Then
With ActiveWorkbook.ActiveSheet
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Sort.SortFields.Clear
.Sort.SortFields.Add(Range("AC1:AC" & lastRow), _
xlSortOnCellColor, xlDescending, , xlSortNormal).SortOnValue.Color = RGB(191, 191, 191)
' ^^ sorts the "gray" (closed) exchanges at the bottom)
.Sort.SortFields.Add Key:=.Range("AC1:AC" & lastRow), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
' ^^ sorts closed files by file close date
.Sort.SortFields.Add Key:=.Range("C1:C" & lastRow), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
' ^^ sorts open files by RQ close date
' THIS IS WHERE CONDITIONS SHOULD BE
' IF no id has been entered, sort by...
' IF id has been entered, sort by...
.Sort.SortFields.Add(Range("K1:K" & lastRow), _
SortOn:=xlSortOnCellColor, Order:=xlDescending, DataOption:=xlSortNormal).SortOnValue.Color = xlNone
' ^^ makes sure that the non-colored rows are sorted??
With .Sort
.SetRange Range("A1:AC" & lastRow)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
lastDrag = .Cells(.Rows.Count, "C").End(xlUp).Row
Range("D2").Select
Selection.AutoFill Destination:=Range("D2:D" & lastDrag), Type:=xlFillDefault
' ^^ this seems to work but it loops forever...
End With
End If
End Sub
目前,excel似乎一直在自动填充,直到崩溃。为什么?
有没有办法让它一次性自动填充列d、e、h、j等(即一堆不相邻的列)?我有些东西像
Range("D2,E2,H2..." & lastDrag)...