简体   繁体   English

Excel VBA运行时错误424

[英]Excel vba runtime error 424

I would like to create a simple macro, which is something like that: 我想创建一个简单的宏,就像这样:

I have a table with serial numbers and 12 columns measurement result for each serial number. 我有一张带有序列号的表,每个序列号的12列测量结果。 There are a tolerance that has a min. 有一个最小公差。 and a max value. 和一个最大值。 I would like to check the results, that if they are in the tolerance field, then set the color of the cell to green. 我想检查结果,如果它们在公差字段中,则将单元格的颜色设置为绿色。

The table is like this: 该表是这样的:

Tabelle屏幕截图

and the tolerance values are: min=250 , max=450 . 公差值为: min=250max=450

I wrote this code, but something is not correct. 我写了这段代码,但是有些不正确。

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

Select your Range and call CallTuresellenorzes : 选择您的范围并致电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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM