大家好日子,目前我仍然面临着我的老板任务的问题,创建一个MS excel宏。
面临的问题仍然存在:
在上一个问题上,我已经问了一些解决方案并将这些建议编码与我原来的编码相结合,但结果也一样,即使有过时的员工合同,该信息仍然会显示为0。
以下是您的建议和我的原始编码的组合......请看一下。
以下是您的建议和我的原始编码的组合...请看看并随意发表评论,让我知道出了什么问题。我尽快需要它..
Sub Worksheet_Activate()
Dim startCell As Integer, endCell As Integer
Dim column As Integer
Dim CountCells As Integer
Dim x As Integer
With Worksheets("Sheet1")
lastrow = Range("L1048576").End(xlUp).Row
For i = 4 To lastrow
If Range("L" & i).Value <> "" And Now <> "" Then
If Range("L" & i).Value <= Now Then
Range("L" & i).Font.ColorIndex = 3
End If
End If
Next i
column = 12 'Column L
startCell = 4
endCell = xlUp
CountCells = 0
For x = startCell To endCell Step 1
If Cells(x, column).Interior.ColorIndex = 3 Then
CountCells = CountCells + 1
End If
Next x
MsgBox CountCells & " expiring"
End With
End Sub
答案 0 :(得分:0)
使用With...End With
时,所有属于With子句的对象都应加上.
(句点)
E.g。
With Worksheets("Sheet1")
lastrow = Range("L1048576").End(xlUp).Row
应该是
With Worksheets("Sheet1")
lastrow = .Range("L1048576").End(xlUp).Row
进行修复,看看是否有帮助。如果仍然无效,请使用当前代码更新您的问题。
答案 1 :(得分:0)
为什么不使用相同的lastrow
而不是创建endCell
,这样可以确保代码在相同的值范围内运行。
您也可以将endCell
更改为
endCell = Range("L1048576").End(xlUp).Row
我认为xlUp
本身不起作用。
编辑:
Sub Worksheet_Activate()
Dim startCell As Integer, endCell As Integer
Dim column As Integer
Dim CountCells As Integer
Dim x As Integer
Dim lastrow As Integer
Dim i As Integer
With Worksheets("Sheet1")
lastrow = Range("L1048576").End(xlUp).Row
For i = 4 To lastrow
If Range("L" & i).Value <> "" And Now <> "" Then
If Range("L" & i).Value <= Now Then
Range("L" & i).Interior.ColorIndex = 3
End If
End If
Next i
column = 12 'Column L
startCell = 4
CountCells = 0
For x = startCell To lastrow Step 1
If Cells(x, column).Interior.ColorIndex = 3 Then
CountCells = CountCells + 1
End If
Next x
MsgBox CountCells & " expiring"
End With
End Sub
答案 2 :(得分:0)
问题已经解决,下面是正确/可用的编码。 感谢大家,只有我能够继续测试和修改编码。
Sub Worksheet_Activate()
Dim startCell As Integer, endCell As Integer
Dim column As Integer
Dim CountCells As Integer
Dim x As Integer
With Worksheets("Sheet1")
lastrow = Range("L1048576").End(xlUp).Row
CountCells = 0
For i = 4 To lastrow
If Range("L" & i).Value <> "" And Now <> "" Then
If Range("L" & i).Value <= Now Then
Range("L" & i).Font.ColorIndex = 3
If Range("L" & i).Font.ColorIndex = 3 Then
CountCells = CountCells + 1
End If
End If
End If
Next i
MsgBox CountCells & " expiring"
End With
End Sub