Excel vba运行时错误424

时间:2017-09-28 09:05:04

标签: excel vba excel-vba runtime-error

我想创建一个简单的宏,就像这样:

每个序列号都有一个包含序列号和12列测量结果的表。有一个公差,有一分钟。和最大值。我想查看结果,如果它们在公差字段中,则将单元格的颜色设置为绿色。

表格如下:

screenshot from the tabelle

,公差值为:min=250max=450

我写了这段代码,但有些不正确。

Sub turesellenorzes()
Dim i As Integer
i = Selection.Value
If (i >= 250 And i <= 450) Then
Selection.Interior.Color = vbGreen
Else: Set Selection.Interior.Color = vbRed
End If

End Sub

1 个答案:

答案 0 :(得分:0)

选择您的范围并致电CallTuresellenorzes

Option Explicit

Sub callturesellenorzes()

Call turesellenorzes(Selection)

End Sub

Sub turesellenorzes(rng As Range)

Dim i As Integer
Dim cell As Range

For Each cell In rng

 If cell >= 250 And cell <= 450 Then

 cell.Interior.Color = vbGreen

 Else

 cell.Interior.Color = vbRed

 End If


Next



End Sub