excel宏报:方法‘value’作用于对象'Range'时失败
PrivateSubWorksheet_selectionChange(ByValTargetAsRange)'''---------------------------...
Private Sub Worksheet_selectionChange(ByVal Target As Range)
'''--------------------------------
If ActiveCell.Row > 1 Then
If (Cells(ActiveCell.Row, 27).Value = "OK") Then
ActiveSheet.Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 30)).Interior.ColorIndex = 35
If (Cells(ActiveCell.Row, 28).Value = "") Then
Cells(ActiveCell.Row, 28).Value = Date
End If
If (Cells(ActiveCell.Row, 30).Value = "") Then
Cells(ActiveCell.Row, 30).Value = Environ("ComputerName")
End If
ElseIf (Cells(ActiveCell.Row, 27).Value = "NOK") Then
ActiveSheet.Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 30)).Interior.ColorIndex = 40
If (Cells(ActiveCell.Row, 28).Value = "") Then
Cells(ActiveCell.Row, 28).Value = Date
End If
If (Cells(ActiveCell.Row, 30).Value = "") Then
Cells(ActiveCell.Row, 30).Value = Environ("ComputerName")
End If
Else: ActiveSheet.Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 30)).Interior.ColorIndex = 0
ActiveSheet.Range(Cells(ActiveCell.Row, 27), Cells(ActiveCell.Row, 30)).Value = ""
End If
End If
'''--------------------------------
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
'''--------------------------------
If ActiveCell.Row > 1 Then
If (Cells(ActiveCell.Row, 27).Value = "OK") Then
ActiveSheet.Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 30)).Interior.ColorIndex = 35
If (Cells(ActiveCell.Row, 28).Value = "") Then
Cells(ActiveCell.Row, 28).Value = Date
End If
If (Cells(ActiveCell.Row, 30).Value = "") Then
Cells(ActiveCell.Row, 30).Value = Environ("ComputerName")
End If
ElseIf (Cells(ActiveCell.Row, 27).Value = "NOK") Then
ActiveSheet.Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 30)).Interior.ColorIndex = 40
If (Cells(ActiveCell.Row, 28).Value = "") Then
Cells(ActiveCell.Row, 28).Value = Date
End If
If (Cells(ActiveCell.Row, 30).Value = "") Then
Cells(ActiveCell.Row, 30).Value = Environ("ComputerName")
End If
Else: ActiveSheet.Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 30)).Interior.ColorIndex = 0
ActiveSheet.Range(Cells(ActiveCell.Row, 27), Cells(ActiveCell.Row, 30)).Value = ""
End If
End If
'''--------------------------------
End Sub
哪位仁兄可以发现这段宏有什么问题,小弟非常感激! 展开
'''--------------------------------
If ActiveCell.Row > 1 Then
If (Cells(ActiveCell.Row, 27).Value = "OK") Then
ActiveSheet.Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 30)).Interior.ColorIndex = 35
If (Cells(ActiveCell.Row, 28).Value = "") Then
Cells(ActiveCell.Row, 28).Value = Date
End If
If (Cells(ActiveCell.Row, 30).Value = "") Then
Cells(ActiveCell.Row, 30).Value = Environ("ComputerName")
End If
ElseIf (Cells(ActiveCell.Row, 27).Value = "NOK") Then
ActiveSheet.Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 30)).Interior.ColorIndex = 40
If (Cells(ActiveCell.Row, 28).Value = "") Then
Cells(ActiveCell.Row, 28).Value = Date
End If
If (Cells(ActiveCell.Row, 30).Value = "") Then
Cells(ActiveCell.Row, 30).Value = Environ("ComputerName")
End If
Else: ActiveSheet.Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 30)).Interior.ColorIndex = 0
ActiveSheet.Range(Cells(ActiveCell.Row, 27), Cells(ActiveCell.Row, 30)).Value = ""
End If
End If
'''--------------------------------
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
'''--------------------------------
If ActiveCell.Row > 1 Then
If (Cells(ActiveCell.Row, 27).Value = "OK") Then
ActiveSheet.Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 30)).Interior.ColorIndex = 35
If (Cells(ActiveCell.Row, 28).Value = "") Then
Cells(ActiveCell.Row, 28).Value = Date
End If
If (Cells(ActiveCell.Row, 30).Value = "") Then
Cells(ActiveCell.Row, 30).Value = Environ("ComputerName")
End If
ElseIf (Cells(ActiveCell.Row, 27).Value = "NOK") Then
ActiveSheet.Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 30)).Interior.ColorIndex = 40
If (Cells(ActiveCell.Row, 28).Value = "") Then
Cells(ActiveCell.Row, 28).Value = Date
End If
If (Cells(ActiveCell.Row, 30).Value = "") Then
Cells(ActiveCell.Row, 30).Value = Environ("ComputerName")
End If
Else: ActiveSheet.Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 30)).Interior.ColorIndex = 0
ActiveSheet.Range(Cells(ActiveCell.Row, 27), Cells(ActiveCell.Row, 30)).Value = ""
End If
End If
'''--------------------------------
End Sub
哪位仁兄可以发现这段宏有什么问题,小弟非常感激! 展开
1个回答
展开全部
试了一下你的代码,当AA列出现"OK"或"NOK"时,会在它后面显示日期及当前计算机的名字.
在测试中未出现错误提示,建议你在代码的第二行设置一个断点,当代码执行到断点时会暂停,然后你通过按键盘上方的F8功能键进行逐语句调试,看一下到哪个语句出现错误.
在测试中未出现错误提示,建议你在代码的第二行设置一个断点,当代码执行到断点时会暂停,然后你通过按键盘上方的F8功能键进行逐语句调试,看一下到哪个语句出现错误.
更多追问追答
追问
你的功能是正确的,但总是运行通不过去,最后会报内存错误,自己一直搞不懂是哪里出错了,您可以帮我检查一下吗?
追答
呵呵,我已经将您的代码复制到我的电脑上测试了,在运行过程未发现任何的错误提示。
也就是说,这个代码在编写上应该是没有问题的,可能是您的EXCEL或者电脑问题。
既然这次又报“内存错误”,应该是电脑硬件方面的问题了,请找电脑维修人员检修一下吧。
祝您早日解决问题
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询