|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 填充()
Application.ScreenUpdating = False
Dim ar As Variant
Dim rn As Range, rng As Range
With Sheets("sheet1")
r = .Cells(Rows.Count, 1).End(xlUp).Row
y = .Cells(4, Columns.Count).End(xlToLeft).Column
If r < 2 Then MsgBox "数据表为空!": End
ar = .Range(.Cells(1, 1), .Cells(r, y))
.Range(.Cells(6, 3), .Cells(r, y)).Interior.ColorIndex = 0
For j = 3 To UBound(ar, 2)
If Trim(ar(3, j)) = "" Then
ar(3, j) = ar(3, j - 1)
End If
If Trim(ar(3, j)) <> "长期" Then
ts = ar(3, j) * 30
For i = 6 To UBound(ar)
If Trim(ar(i, j)) <> "" Then
If IsDate(ar(i, j)) Then
ys = DateDiff("d", ar(i, j), Date)
If ts - ys <= 60 And ts - ys > 0 Then
If rn Is Nothing Then
Set rn = .Cells(i, j)
Else
Set rn = Union(rn, .Cells(i, j))
End If
ElseIf ys > ts Then
If rng Is Nothing Then
Set rng = .Cells(i, j)
Else
Set rng = Union(rng, .Cells(i, j))
End If
End If
End If
End If
Next i
End If
Next j
If Not rn Is Nothing Then rn.Interior.ColorIndex = 6
If Not rng Is Nothing Then rng.Interior.ColorIndex = 3
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|