对象'_worksheet'的方法'范围'失败,无法解决

时间:2016-07-13 17:04:53

标签: excel-vba error-handling worksheet vba excel

每次代码运行时都会出现一个小问题。我试图多次更改代码,但我仍然遇到同样的问题。我觉得错误是与工作表对象有关但我无法解决它!任何帮助表示赞赏。

Sub Worksheet_Change(ByVal Target As Excel.Range)

Dim LastRow4 As Long

If Worksheets("Sheet1").Range("D12").Value = "Decrease" Then

If Worksheets("Sheet1").Range("D11").Value >= Worksheets("Sheet1").Range("U1").End(xlDown).Value Then

With ActiveSheet.Shapes("Chart 1").Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(146, 208, 80)
    .Transparency = 0
    .Solid
End With

ElseIf Worksheets("Sheet1").Range("D11") < Worksheets("Sheet1").Range("U1").End(xlDown).Value Then

With ActiveSheet.Shapes("Chart 1").Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(255, 0, 0)
    .Transparency = 0
    .Solid
End With
End If

ElseIf Worksheets("Sheet1").Range("D12").Value = "Increase" Then
If Worksheets("Sheet1").Range("D11").Value >= Worksheets("Sheet1").Range("U1").End(xlDown).Value Then

With ActiveSheet.Shapes("Chart 1").Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(255, 0, 0)
    .Transparency = 0
    .Solid
End With
ElseIf Worksheets("Sheet1").Range("D11") < Worksheets("Sheet1").Range("U1").End(xlDown).Value Then

With ActiveSheet.Shapes("Chart 1").Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(146, 208, 80)
    .Transparency = 0
    .Solid
End With
End If
End If


LastRow4 = Worksheets("Sheet1").Range("U" & Rows.Count).End(xlUp).Row
Worksheets("Sheet1").Range("D11").Copy Worksheets("Sheet1").Range("W2:W" & LastRow4)
Application.CutCopyMode = False

  End Sub

0 个答案:

没有答案